简体   繁体   English

缩放图后如何保存图

[英]How to save plot after the plot is zoomed

Last few days I have been facing a problem in saving the matplotlib figure, three days before the code was working fine and saves the plot with changes made through the code, but now the changes (zoomed plot) is not saving rather it saves as it is when the plot is shown any changes made after does not reflects using the save command, don't know why? 最近几天,我在保存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

even if I call a function, the new changed plot is not saved... 即使我调用函数,也不会保存新更改的图...

    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')

How do I save the plot (zoomed one with changes) through code? 如何通过代码保存绘图(缩放后的图)?
Note: I have noticed that the plot window appearance is also changed, 注意:我注意到绘图窗口的外观也发生了变化,
1 Plot window appearance before 1绘制窗口外观之前
2 Plot window appearance now 2现在绘制窗口外观
all the plot window configuration buttons are shifted from bottom to top, does this change affects only in the plot or affects the coding as well?. 所有绘图窗口配置按钮都从底部移到顶部,此更改是否只影响绘图或编码? Please help me to fix this... 请帮我解决这个问题...
Thanks in advance. 提前致谢。

You could move all the plot changing code above the plt.show() and then save the figure manually from the pop-up window. 您可以将所有绘图更改代码plt.show()上方,然后从弹出窗口中手动保存图形。 The right most icon at the bottom left saves the current figure as is currently displayed 左下方最右边的图标会将当前图形保存为当前显示的状态

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM