朱莉娅:如何保存图形而不在PyPlot中绘制/显示它? [英] Julia: How to save a figure without plotting/displaying it in PyPlot?

查看:374
本文介绍了朱莉娅:如何保存图形而不在PyPlot中绘制/显示它?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Julia中的PyPlot包来生成并保存多个图形.我当前的方法是显示图形,然后使用savefig保存.

I am using the PyPlot package in Julia to generate and save several figures. My current approach is to display the figure and then save it using savefig.

using PyPlot
a = rand(50,40)
imshow(a)
savefig("a.png")

有没有一种方法可以保存图形而不必先显示它?

Is there a way to save the figure without having to first display it?

推荐答案

您是否正在使用REPL或IJulia?

Are you using the REPL or IJulia?

如果关闭该图,则不会显示该图.那是你想要的吗?

If you close the figure then it won't show you the plot. Is that what you want?

a = rand(50,40)
ioff() #turns off interactive plotting
fig = figure()
imshow(a)
close(fig)

如果这不起作用,则可能需要使用ioff()关闭交互式绘图或更改matplotlib后端(pygui(:Agg))(请参见此处:

If that doesn't work you might need to turn off interactive plotting using ioff() or change the matplotlib backend (pygui(:Agg)) (see here: Calling pylab.savefig without display in ipython)

请记住,大多数有关使用PyPlot进行绘图的问题都可以通过阅读python社区的答案来解决.并且还使用 https://github.com/JuliaPy/PyPlot.jl 上的文档来在两者之间翻译:)

Remember that most questions about plotting using PyPlot can be worked out by reading answers from the python community. And also using the docs at https://github.com/JuliaPy/PyPlot.jl to translate between the two :)

这篇关于朱莉娅:如何保存图形而不在PyPlot中绘制/显示它?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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