绘图缩放后如何保存绘图

时间:2014-07-16 10:50:46

标签: python matplotlib plot

最近几天,我一直面临着保存matplotlib图的问题,在代码工作正常前三天,并通过代码进行了更改保存了图,但现在更改(缩放图)并没有保存而是保存保存,因为当显示图表后所做的任何更改都没有反映使用save命令,不知道为什么?

    ax = pd.rolling_mean(dataToPlot_plot[startTime:endTime][['plotValue']],mar).plot(linestyle='-', linewidth=3,  markersize=9, color='#FECB00')
            ax.legend().set_visible(False)
    plt.show()#showing the plot
    fig = ax.get_figure()
    fig.set_size_inches(12, 6)#setting the size of the plot, to fix in the PDF file
    fig.savefig('graph1.jpg')#saving the plot

即使我调用了一个函数,也不会保存新更改的图...

    def callmeto_plot()
            ax = pd.rolling_mean(dataToPlot_plot[startTime:endTime][['plotValue']],mar).plot(linestyle='-', linewidth=3,  markersize=9, color='#FECB00')
            ax.legend().set_visible(False)
            plt.show()#showing the plot
            fig = ax.get_figure()

            return fig

    fig = callmeto_plot()
    fig.set_size_inches(12, 6)
    fig.savefig('graph1.jpg')

如何通过代码保存绘图(通过更改缩放)?
注意:我注意到情节窗口的外观也发生了变化,在1绘图窗口出现之前,2绘图窗口外观为全部绘图窗口配置按钮从下到上移动,此更改是否仅影响绘图或影响编码?请帮我解决这个问题......
提前致谢。

1 个答案:

答案 0 :(得分:0)

您可以将所有绘图更改代码移到plt.show()上方,然后从弹出窗口手动保存图形。左下角最右边的图标保存当前显示的当前数字

更好的是,您可以使用plt.axis([xStart, xFinish, yBottom, yTop])ax.set_xlim(), ax.set_ylim

相关问题