问题描述
我目前有一个 python 程序,它能够根据用户要求的数据生成堆积条形图。目前,它只显示一个简单的 plt.show()
。这是调用的函数:
# Create and displays a stacked bar chart from the given data and options
def stacked_bar_chart(all_values: list[list[int]],legend: list[str],labels: list[str] = None,title: str = None,ylabel: str = None):
plt.bar(labels,all_values[0])
bottom = all_values[0]
for i in range(1,len(all_values)):
plt.bar(labels,all_values[i],bottom=bottom)
for j in range(len(bottom)):
bottom[j] += all_values[i][j]
plt.title(title)
plt.ylabel(ylabel)
plt.xticks(labels)
plt.legend(legend)
plt.show()
问题是,现在我希望能够多次调用此函数,每次都返回图表,然后将这些图保存在 pdf 文件中。但我从来没有找到如何在网上做这件事,我在互联网上找到的唯一保存条形图表的方法是做graph = plt.bar(...)
,因为我创建了多个条形图,这在这里不起作用在堆积条形图中。有没有办法解决这个问题?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)