我在python中用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的图片。在
我找不到这方面的任何信息。在
看看} 示例。在
matplotlib
文档中的^{基本思想是您不使用来自} 方法,而是使用^{} 自己构建条形图。
pyplot
的^{imshow()
的第一个参数包含颜色映射,它将显示在extent
参数指定的框内。在你应该在上面的例子中找到一个简化版本。它使用Excel示例中的值,以及使用CSS colors“道奇蓝”和“皇家蓝”作为线性渐变的颜色贴图。在
相关问题 更多 >
编程相关推荐