![](/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.