简体   繁体   English

无法为堆叠条形图设置 label

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

I am trying to set labels for the y-axis and secondary y-axis, however, I am unable to set a label for the y-axis, help is highly appreciated.我正在尝试为 y 轴和辅助 y 轴设置标签,但是,我无法为 y 轴设置 label,非常感谢帮助。 Using this code plt.ylabel("data (MB)") is setting label for secondary y-axis, I need label for x, y and secondary y-axis.使用此代码 plt.ylabel("data (MB)") 将 label 设置为辅助 y 轴,我需要 label 用于 x、y 和辅助 y 轴。 Thanks谢谢

 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)")

Putting a plt.ylabel('Text') before plotting the second plot works.在绘制第二个 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