Python:matplotlib绘图时指定图像大小,放大图像

您所在的位置:网站首页 图片无限缩小怎么弄出来 Python:matplotlib绘图时指定图像大小,放大图像

Python:matplotlib绘图时指定图像大小,放大图像

2024-07-13 21:55| 来源: 网络整理| 查看: 265

matplotlib绘图时是默认的大小,有时候默认的大小会感觉图片里的内容都被压缩了,解决方法如下。 先是原始代码:

from matplotlib import pyplot as plt plt.figure(figsize=(1,1)) x = [1,2,3] plt.plot(x, x) plt.show()

关键的代码是plt.figure(figsize=(1,1)),生成的图片如下 在这里插入图片描述 修改代码,放大图片:

from matplotlib import pyplot as plt plt.figure(figsize=(10,10)) x = [1,2,3] plt.plot(x, x) plt.show()

这时候横坐标和纵坐标都放大了10倍: 在这里插入图片描述

如果想要指定像素,可以这么做:

from matplotlib import pyplot as plt plt.figure(dpi=80) x = [1,2,3] plt.plot(x, x) plt.show()

在这里插入图片描述

更多参考资料:python - How do you change the size of figures drawn with matplotlib? - Stack Overflow



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3