0
我有蟒蛇我已经和matplotlib用下面的代码的图形:如何着色MatPlotLib图形使用渐变色
def to_percent(y, position):
s = str(250 * y)
if matplotlib.rcParams['text.usetex'] is True:
return s + r'$\%$'
else:
return s + '%'
distance = df['Distance']
perctile = np.percentile(distance, 90) # claculates 90th percentile
bins = np.arange(0,perctile,2.5) # creates list increasing by 2.5 to 90th percentile
plt.hist(distance, bins = bins, normed=True)
formatter = FuncFormatter(to_percent) #changes y axis to percent
plt.gca().yaxis.set_major_formatter(formatter)
plt.axis([0, perctile, 0, 0.10]) #Defines the axis' by the 90th percentile and 10%Relative frequency
plt.xlabel('Length of Trip (Km)')
plt.title('Relative Frequency of Trip Distances')
plt.grid(True)
plt.show()
我想知道的是什么,是可以使用渐变而不是块颜色对条进行着色,就像在Excel中的这张图片中一样。
我已经无法找到这方面的消息。
不用调用'hist',你可以使用'numpy.histogram'并用'bar'绘图。然后[文档示例](http://matplotlib.org/examples/pylab_examples/gradient_bar.html)将适用。 – wflynny
[如何用渐变填充matplotlib栏?]可能重复(http://stackoverflow.com/questions/38830250/how-to-fill-matplotlib-bars-with-a-gradient) – wflynny