Matplotlib savefig不保存轴 [英] Matplotlib savefig does not save axes

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

问题描述

我正在尝试保存一个在 IPython 内联中工作正常的图形,但没有将图形保存到包含轴和标题的磁盘中.

I'm trying to save a figure that works fine in IPython inline but does not save the figure to disk with the axes and titles included.

默认情况下,我在matplotlibrc中使用TKAgg后端

I am using TKAgg backend by default in matplotlibrc

任何想法这里可能出了什么问题?我已经清楚地设置了 xlabel 和刻度线在 IPython 内嵌图中正常工作.

Any ideas what might be going wrong here? I have clearly set the xlabel and tick marks work correctly in IPython inline plot.

   import matplotlib.pylab as plt  
    x = [1,2,3,3]
    y = map(lambda(x): x * 2, x)
    fig = plt.figure()
    ax = fig.add_axes([0,0,1,1])
    ax.set_title("bleh")
    ax.set_xlabel("xlabel")
    ax.plot(x, y, 'r--')
    fig.savefig("fig.png")

推荐答案

我在使用Jupyter笔记本和以下命令时遇到了相同的问题:%matplotlib笔记本.该图在笔记本中正确显示,但在使用 fig.savefig() 保存时未打印轴和标题.我将 %matplotlib notebook 内联更改为 %matplotlib 并解决了问题.

I was having the same problem using Jupyter notebook and the command: %matplotlib notebook. The figure showed correctly in the notebook but didn't print axis and titles when saved with fig.savefig(). I changed %matplotlib notebook to %matplotlib inline and that solved the problem.

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

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