回答(15)
2 years ago
我使用了以下内容:
import matplotlib.pyplot as plt
p1 = plt.plot(dates, temp, 'r-', label="Temperature (celsius)")
p2 = plt.plot(dates, psal, 'b-', label="Salinity (psu)")
plt.legend(loc='upper center', numpoints=1, bbox_to_anchor=(0.5, -0.05), ncol=2, fancybox=True, shadow=True)
plt.savefig('data.png')
plt.show()
f.close()
plt.close()
我发现在保存图形后使用plt.show非常重要,否则它将无法工作 . figure exported in png
2 years ago
如果像我一样使用Spyder IDE,则必须禁用交互模式:
plt.ioff()
(此命令随科学启动自动启动)
如果要再次启用它,请使用:
plt.ion()
2 years ago
#write the code for the plot
plt.savefig("filename.png")
该文件将保存在与运行的python / Jupyter文件相同的目录中
2 years ago
import datetime
import numpy as np
from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.pyplot as plt
# Create the PdfPages object to which we will save the pages:
# The with statement makes sure that the PdfPages object is closed properly at
# the end of the block, even if an Exception occurs.
with PdfPages('multipage_pdf.pdf') as pdf:
plt.fi