微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

使用样式时,matplotlib savefig 与显示的图像不同

如何解决使用样式时,matplotlib savefig 与显示的图像不同

我有以下代码来绘制数据。绘图以灰色背景绘制,但当我保存图形时,它没有网格或背景。

如何使用与样式(带有网格线和灰色背景)内联绘制的相同属性保存绘图

from matplotlib import rc
import matplotlib.pyplot as plt
from numpy.random import Generator,PCG64

plt.style.use('ggplot')
fig,ax = plt.subplots(frameon=False)
rc('mathtext',default='regular')
rc('text',usetex=True)

rg = Generator(PCG64(12345))
Y = np.random.uniform(size=(25,2))
ax.scatter(Y[:,0],Y[:,1])
ax.tick_params(axis="both",colors="white")
fig.savefig('plot.pdf',format='pdf',transparent=True,dpi=fig.dpi,facecolor=fig.get_facecolor(),edgecolor=fig.get_edgecolor())

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。