python - 一次处理多个绘图对象
问题描述
我有一个带有循环的方法,它创建由给定数据框的列表输入给出的多个箱线图:
def create_boxplots(data_frame):
x_axis_attr = [columnA, columnB, columnC]
for index in range(len(x_axis_attr)):
boxplot = sns.boxplot(x=data_frame[x_axis_attr[index]])
plot_dict.update({"boxplot " + x_axis_attr[index]: boxplot})
return plot_dict
绘图保存由不同的模块处理,因此创建的绘图在 dict() 中返回。
事实证明,这些图没有保存在不同的对象中:
[<matplotlib.axes._subplots.AxesSubplot object at 0x181640D0>,
<matplotlib.axes._subplots.AxesSubplot object at 0x181640D0>,
<matplotlib.axes._subplots.AxesSubplot object at 0x181640D0>]
即使我用以下方式保存数字boxplot.get_figure()
:
[<matplotlib.figure.Figure object at 0x18C37F30>,
<matplotlib.figure.Figure object at 0x18C37F30>,
<matplotlib.figure.Figure object at 0x18C37F30>]
注意:1.如果plt.show()
在循环中执行,所有箱线图都正确显示
如何确保所有地块都有自己的对象并且不共享内存?提前致谢
解决方案
推荐阅读
- ruby-on-rails - 如何在 GraphQL 中使用 image_url 助手?
- javascript - 在 javascript 中写入 CSV 文件列标题
- azure - 如何在规模集 VM 之间有效共享数据
- android - Firebase Auth EmailAndPassword 和实时数据库错误
- entity-framework - 无法使用 GitLab CI 脚本中的 EF Core 连接到 AWS 数据库
- python - 矢量化张量流步骤的正确方法
- javascript - Font Awesome 5,如何设置 svg 伪元素的样式?
- wso2 - wso2 esb如何连接和查询到HBASE
- sql - 根据另一个 SQL 中最近的日期返回表中的值
- vba - 使用 VBA 引用另一个工作表中的单元格,该工作表本身由其文本引用