How to make pylab.savefig() save image for 'maximized' window instead of default size

前端 未结 8 2222
一整个雨季
一整个雨季 2020-12-12 17:49

I am using pylab in matplotlib to create a plot and save the plot to an image file. However, when I save the image using pylab.savefig( image_name ), I find tha

8条回答
  •  Happy的楠姐
    2020-12-12 18:51

    You can look in a saved figure it's size, like 1920x983 px (size when i saved a maximized window), then I set the dpi as 100 and the size as 19.20x9.83 and it worked fine. Saved exactly equal to the maximized figure.

    import numpy as np
    import matplotlib.pyplot as plt
    x, y = np.genfromtxt('fname.dat', usecols=(0,1), unpack=True)
    a = plt.figure(figsize=(19.20,9.83))
    a = plt.plot(x, y, '-')
    plt.savefig('file.png',format='png',dpi=100)
    

提交回复
热议问题