![](/img/trans.png)
[英]How to fill between the lines in a pandas/matplotlib time series plot
[英]How to plot comparison between two categorical (Nominal) series with pandas and matplotlib
我正在尝试比较一系列元素的两种不同分类。 假设我要获得这样的图形:
通过以下iPython会话获得:
In [1]: df
Out[1]:
<class 'pandas.core.frame.DataFrame'>
Index: 446 entries, element0 to element445
Data columns (total 2 columns):
Classification1 446 non-null values
Classification2 446 non-null values
dtypes: int64(2)
In [2]: pylab.pcolor(df, cmap='Oranges')
Out[2]: <matplotlib.collections.PolyCollection at 0x55dc650>
In [3]: pl.show()
1)如何查看两个分类中是否将相同的颜色用于相同的值? IE浏览器。 如何测试在两个分类中具有相同颜色的element1是否也具有相同的值(例如,在分类1和分类2中都被分类为1)? 我尝试使用pl.legend()
但它告诉我:
In [54]: pl.legend()
/usr/lib/pymodules/python2.7/matplotlib/axes.py:4486: UserWarning: No labeled objects found. Use label='...' kwarg on individual plots.
warnings.warn("No labeled objects found. "
2)是否有更好的方法以图形方式比较两个分类?
谢谢
与以前的答案相比,我认为这更符合您的需求
levels = [0.0, 1.0, 2.0]
a = np.random.choice(levels, size=10)
a_array = np.vstack((a, a)).T
b = np.random.choice(levels, size=10)
b_array = np.vstack((b, b)).T
ax = plt.subplot(121)
CS = ax.contourf(a_array, 2, level=levels, colors=('r', 'g', 'b'))
ax = plt.subplot(122)
CS = ax.contourf(b_array, 2, level=levels, colors=('r', 'g', 'b'))
Cbar = plt.colorbar(CS)
Cbar.set_ticks(levels)
Cbar.set_ticklabels(["series 1", "series 2", "series 3"])
据我所知, pcolor
无法以这种方式设置标签。 尽管如果可能的话,q将是更好的方法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.