Matplotlib is a plotting library for Python. It works with NumPy, providing an effective open source alternative to MatLab. It can also be used with graphical toolkits such as PyQt and wxPython.
#For image size, Matplotlib provides the following methods to handle it.
matplotlib.rcParams['figure.figsize']#Picture pixels
matplotlib.rcParams['savefig.dpi']#Resolution
plt.savefig ('plot123_2.png', dpi=200)#Specify resolution
Sample code:
plt.rcParams['figure.figsize'] = (8.0, 4.0) # 设置figure_size尺寸 plt.rcParams['image.interpolation'] = 'nearest' # 设置 interpolation style plt.rcParams['image.cmap'] = 'gray' # 设置 颜色 style #figsize(12.5, 4) # 设置 figsize plt.rcParams['savefig.dpi'] = 300 #图片像素 plt.rcParams['figure.dpi'] = 300 #分辨率 # 默认的像素:[6.0,4.0],分辨率为100,图片尺寸为 600&400 # 指定dpi=200,图片尺寸为 1200*800 # 指定dpi=300,图片尺寸为 1800*1200 # 设置figsize可以在不改变分辨率情况下改变比例
The above is the detailed content of How to change matplotlib image size. For more information, please follow other related articles on the PHP Chinese website!