我有一個直方圖的副圖。底部的plt.legend創建了一個重複顏色的圖例。在這張截圖的子圖的一部分,python matplotlib圖例重複
「激醒」是相同的顏色爲「睡眠REM」
如何改變圖表的顏色和圖例,以便他們所有獨特?
def create_histogram(grouped, axs, df):
bin_size = 100
alpha = 0.5
grouped = df.groupby('Label')
bins = np.linspace(df.Capacitor_1.min(), df.Capacitor_1.max(), bin_size)
series = grouped.Capacitor_1
series.plot(kind = 'hist', title = "Capacitor 1", ax = axs[0][0] , bins = bins, alpha = alpha)
...
bins = np.linspace(df.Mag_Z.min(), df.Mag_Z.max(), bin_size)
series = grouped.Mag_Z
series.plot(kind = 'hist', title = "Mag Z", ax = axs[3][2], bins = bins, alpha = alpha)
fig, axs = plt.subplots(nrows = 4, ncols = 3, figsize = (20, 40))
fig.subplots_adjust(hspace = .5)
grouped = df_left.groupby('Label')
create_histogram(grouped, axs, df_left)
plt.legend(bbox_to_anchor = (0.98, 0.8))
plt.show()
你定義你自己的一套(循環)的顏色。 https://matplotlib.org/examples/color/color_cycle_demo.html上的簡單示例,以及https://matplotlib.org/gallery.html#color中的可用顏色。 – Evert
@避免您的評論幫助。謝謝。 –