Matplotlib - 如何绘制高分辨率图形?

新手上路,请多包涵

我已经使用 matplotlib 绘制了一些实验结果(在这里讨论过: Looping over files and plotting 。但是,通过在图像上单击右键来保存图片会产生非常差的质量/低分辨率图像。

 from glob import glob
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl

# loop over all files in the current directory ending with .txt
for fname in glob("./*.txt"):
    # read file, skip header (1 line) and unpack into 3 variables
    WL, ABS, T = np.genfromtxt(fname, skip_header=1, unpack=True)

    # first plot
    plt.plot(WL, T, label='BN', color='blue')

    plt.xlabel('Wavelength (nm)')
    plt.xlim(200,1000)
    plt.ylim(0,100)
    plt.ylabel('Transmittance, %')
    mpl.rcParams.update({'font.size': 14})
    #plt.legend(loc='lower center')
    plt.title('')
    plt.show()
    plt.clf()

    # second plot
    plt.plot(WL, ABS, label='BN', color='red')
    plt.xlabel('Wavelength (nm)')
    plt.xlim(200,1000)
    plt.ylabel('Absorbance, A')
    mpl.rcParams.update({'font.size': 14})
    #plt.legend()
    plt.title('')
    plt.show()
    plt.clf()

我正在寻找的示例图: example graph

原文由 esilik 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 457
2 个回答

您可以使用 savefig() 导出到图像文件:

 plt.savefig('filename.png')

此外,您可以将 dpi 参数指定为某个标量值,例如:

 plt.savefig('filename.png', dpi=300)

原文由 Ohad Eytan 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题