在为循环生成的一个图上绘制多个图形
我有一个数据帧字典,并且正在使用以下代码为dict中的每个数据框架生成堆叠的条形图。该代码按预期打印每个堆叠的条形图(每个图表都在笔记本中彼此之间,在笔记本中彼此之间),但我希望它在一个图上打印每个图表,例如,可以说4行带有3列。
for i, key in enumerate(d):
plt.rcParams["figure.figsize"] = (5,3)
d[key].plot(kind = 'barh', width= 0.85, stacked = True, color = ['limegreen','gold', 'orange', 'red'])
plt.legend(bbox_to_anchor = (1.05, 1.025), title = "Categories")
plt.xlabel('Cumulative Percent')
plt.gca().xaxis.set_major_formatter(mtick.PercentFormatter())
plt.ylabel('Data Stream')
plt.gca().invert_yaxis()
plt.title(f'{key}')
plt.show()
I have a dictionary of data frames and I am using the below code to generate a stacked bar chart for every data frame within the dict. The code prints every stacked bar chart as intended (each graph one after the other and below each other in notebook), but I want it to print each chart on one figure, lets say 4 rows with 3 columns for example.
for i, key in enumerate(d):
plt.rcParams["figure.figsize"] = (5,3)
d[key].plot(kind = 'barh', width= 0.85, stacked = True, color = ['limegreen','gold', 'orange', 'red'])
plt.legend(bbox_to_anchor = (1.05, 1.025), title = "Categories")
plt.xlabel('Cumulative Percent')
plt.gca().xaxis.set_major_formatter(mtick.PercentFormatter())
plt.ylabel('Data Stream')
plt.gca().invert_yaxis()
plt.title(f'{key}')
plt.show()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
更多
发布评论
评论(1)
使用子图:
输出:

using subplots:
output:
