保存交互式Matplotlib图形 [英] Saving interactive Matplotlib figures

查看:248
本文介绍了保存交互式Matplotlib图形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有一种方法可以保存Matplotlib图形,以便可以重新打开它并恢复典型的交互作用? (就像MATLAB中的.fig格式一样?)

Is there a way to save a Matplotlib figure such that it can be re-opened and have typical interaction restored? (Like the .fig format in MATLAB?)

我发现自己多次运行相同的脚本来生成这些交互式图形.或者我要向同事发送多个静态PNG文件,以显示绘图的不同方面.我宁愿发送图形对象,并让它们自己与之交互.

I find myself running the same scripts many times to generate these interactive figures. Or I'm sending my colleagues multiple static PNG files to show different aspects of a plot. I'd rather send the figure object and have them interact with it themselves.

推荐答案

这将是一个很棒的功能,但是AFAIK并未在Matplotlib中实现,并且由于数字的方式可能很难实现自己存储.

我建议要么(a)将数据处理与生成图形分开(以唯一的名称保存数据),然后编写图形生成脚本(加载已保存数据的指定文件)并根据需要进行编辑或(b)另存为PDF/ SVG / Adob​​e Illustrator (或 Inkscape ).

I'd suggest either (a) separate processing the data from generating the figure (which saves data with a unique name) and write a figure generating script (loading a specified file of the saved data) and editing as you see fit or (b) save as PDF/SVG/PostScript format and edit in some fancy figure editor like Adobe Illustrator (or Inkscape).

2012年秋季发布的帖子:正如下面其他人所指出的(尽管在此提及,因为这是公认的答案),自1.2版以来,Matplotlib允许您腌制人物.由于发行说明状态,这是实验性的功能,并且不支持在一个matplotlib版本中保存图形并在另一个版本中打开.从不受信任的来源恢复泡菜通常也是不安全的.

EDIT post Fall 2012: As others pointed out below (though mentioning here as this is the accepted answer), Matplotlib since version 1.2 allowed you to pickle figures. As the release notes state, it is an experimental feature and does not support saving a figure in one matplotlib version and opening in another. It's also generally unsecure to restore a pickle from an untrusted source.

对于共享/以后的编辑图(首先需要进行大量数据处理,并且可能需要在几个月后进行调整,例如在发表科学论文的同行评审中进行调整),我仍然建议(1)的工作流程使用数据处理脚本,在此之前生成图会将已处理的数据(进入您的图)保存到文件中,并且(2)具有单独的图生成脚本(您可以根据需要进行调整)以重新创建图.通过这种方式,您可以为每个绘图快速运行脚本并重新生成脚本(并使用新数据快速复制绘图设置).话虽如此,腌制一个数字可能便于进行短期/交互式/探索性数据分析.

For sharing/later editing plots (that require significant data processing first and may need to be tweaked months later say during peer review for a scientific publication), I still recommend the workflow of (1) have a data processing script that before generating a plot saves the processed data (that goes into your plot) into a file, and (2) have a separate plot generation script (that you adjust as necessary) to recreate the plot. This way for each plot you can quickly run a script and re-generate it (and quickly copy over your plot settings with new data). That said, pickling a figure could be convenient for short term/interactive/exploratory data analysis.

这篇关于保存交互式Matplotlib图形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆