python - 在 Jupyter Notebook 中增加 Matplotlib .show() 的 DPI

标签 python matplotlib jupyter-notebook

我在 Jupyter Notebook 中使用 Matplotlib 来显示 map 图像。代码如下所示:

%matplotlib inline

imgpath = './map.png'

import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np

from PIL import Image

img = Image.open(imgpath)
print(img.size)

width, height = img.size
# img.thumbnail((width * 2,height * 2), Image.ANTIALIAS)  # resizes image in-place
imgplot = plt.imshow(img)
plt.savefig('test.png', dpi = 300)

问题是,虽然 plt.savefig('test.png', dpi = 300) 看起来不错(因为我将 dpi 更改为 300),但笔记本中显示的图像是如此低分辨率我无法在上面做任何事情,plt.imshow(img, dpi = 300) 不起作用:

Image displayed in notebook

所以我想知道是否有办法更改 Jupyter Notebook 中显示的图像的分辨率?

最佳答案

在笔记本的开头添加:

import matplotlib as mpl
mpl.rcParams['figure.dpi'] = 300

就是这样!

关于python - 在 Jupyter Notebook 中增加 Matplotlib .show() 的 DPI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51937381/

相关文章:

python - Django 会自动检测最终用户的时区吗?

python - 爬虫对象与蜘蛛、管道对象有什么关系?

python - 将 dtype 对象的 numpy 数组转换为 dtype complex

python - 如果嵌入了 Python,如何从 C 执行 .py 脚本?

python - matplotlib 轴刻度标签 : getting mantissa and exponent

python - Matplotlib basemap 海岸坐标

python - 获取条形图的颜色matplotlib

python-2.7 - 更改Jupyter Notebook服务器密码

python - 将 pandas 的元组列转换为 MultiIndex

python - 为什么我的散点图没有显示颜色?