使用样式时,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 (将#修改为@)