简体   繁体   English

如何在 Python Pandas 中保存绘图

[英]How to save a plot in Python Pandas

This code.:此代码。:

import matplotlib.pyplot as plt

fig = plt.get_figure()
fig.savefig("myplot1.pdf")

Gives the following error:给出以下错误:

AttributeError: 'module' object has no attribute 'get_figure'

How can I amend this?我该如何修改?

First of all check whether a function exists or not in a module or library then only proceed.首先检查模块或库中是否存在函数,然后才继续。 Also please explain the question with relevant or example data.另外请用相关或示例数据解释问题。

You can save the figure in matplotlib.pyplot as shown.您可以将图形保存在 matplotlib.pyplot 中,如图所示。

import matplotlib.pyplot as plt

plt.scatter(x=[0,1,2,3,4,5],y=[0,1,2,3,4,5])
plt.savefig('saved_figure') #figure will be saved as saved_figure.png
plt.savefig('saved_figure.pdf') #figure will be saved as saved_figure.pdf

The Saved Figure will look like this and it will be saved in working directory.保存的图形将如下所示,并将保存在工作目录中。

The Saved Figure in pdf format. pdf 格式的保存图

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

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