簡體   English   中英

無法為堆疊條形圖設置 label

[英]Unable to set a label for stacked bar graph

我正在嘗試為 y 軸和輔助 y 軸設置標簽,但是,我無法為 y 軸設置 label,非常感謝幫助。 使用此代碼 plt.ylabel("data (MB)") 將 label 設置為輔助 y 軸,我需要 label 用於 x、y 和輔助 y 軸。 謝謝

 m1_t = pd.DataFrame({
 'device1': [13.22,43.20,146.38],
 'device2':[609.52,663.49,591.76],
 'comm':[230,5010,5010],
 'data':[12.545,12.545,3.137
  })
 colors = ['#5DADE2', '#48C9B0', '#D5DBDB']
 m1_t[['device1','device2','comm']].plot(kind='bar', width = 
 width,stacked=True,color=colors)
 m1_t['data'].plot(secondary_y=True,color='darkslategrey',marker='o',MarkerSize= 3)
 ax = plt.gca()
 plt.xlim([-width, len(m1_t['comm'])-width])
 ax.set_xticklabels(("1", "2", "3"))
 plt.ylabel("data (MB)")

在繪制第二個 plot 之前放置一個plt.ylabel('Text')有效。

m1_t = pd.DataFrame({
 'device1': [13.22,43.20,146.38],
 'device2':[609.52,663.49,591.76],
 'comm':[230,5010,5010],
 'data':[12.545,12.545,3.137]})
colors = ['#5DADE2', '#48C9B0', '#D5DBDB']
width = 0.2

m1_t[['device1','device2','comm']].plot(kind='bar', width = width, stacked=True, color=colors)
plt.ylabel("Count") #here
plt.xlabel('Device')

m1_t['data'].plot(secondary_y=True, color='darkslategrey', marker='o',MarkerSize= 3)
ax = plt.gca()
plt.xlim([-width, len(m1_t['comm'])-width])
ax.set_xticklabels(("1", "2", "3"))
plt.ylabel("data (MB)")

plt.show()

在此處輸入圖像描述

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM