Home  >  Article  >  Backend Development  >  How to change matplotlib image size

How to change matplotlib image size

anonymity
anonymityOriginal
2019-05-25 14:15:226726browse

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.

How to change matplotlib image size

#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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn