我试图通过孵化模式而不是(仅仅)颜色来实现差异化。我怎么用熊猫来做呢?
在matplotlib中,可以通过传递hatch可选参数(如讨论的这里 )。我知道我也可以把这个选项传递给熊猫plot,但我不知道如何告诉它对每个DataFrame列使用不同的孵化模式。
df = pd.DataFrame(rand(10, 4), columns=['a', 'b', 'c', 'd'])
df.plot(kind='bar', hatch='/');

对于颜色,有colormap选项描述这里。孵化有类似的东西吗?或者我可以通过修改Axes返回的plot对象来手动设置它。
发布于 2014-04-03 11:33:46
这有点烦人,但很管用:
df = pd.DataFrame(np.random.rand(10, 4), columns=['a', 'b', 'c', 'd'])
ax = plt.figure(figsize=(10, 6)).add_subplot(111)
df.plot(ax=ax, kind='bar', legend=False)
bars = ax.patches
hatches = ''.join(h*len(df) for h in 'x/O.')
for bar, hatch in zip(bars, hatches):
bar.set_hatch(hatch)
ax.legend(loc='center right', bbox_to_anchor=(1, 1), ncol=4)

发布于 2018-01-29 18:45:37
在定义模式时,这段代码允许您有更多的自由,这样您就可以拥有'//‘等。
bars = ax.patches
patterns =('-', '+', 'x','/','//','O','o','\\','\\\\')
hatches = [p for p in patterns for i in range(len(df))]
for bar, hatch in zip(bars, hatches):
bar.set_hatch(hatch)https://stackoverflow.com/questions/22833404
复制相似问题