程序员最近都爱上了这个网站  程序员们快来瞅瞅吧!  it98k网:it98k.com

本站消息

站长简介/公众号

  出租广告位,需要合作请联系站长

+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

2023-05(3)

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

发布于2019-08-07 11:37     阅读(779)     评论(0)     点赞(0)     收藏(0)


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

from matplotlib import pyplot as plt

plt.figure(figsize=(1,1))

x = [1,2,3]
plt.plot(x, x)
plt.show()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

关键的代码是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()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

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

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

from matplotlib import pyplot as plt

plt.figure(dpi=80)

x = [1,2,3]
plt.plot(x, x)
plt.show()
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7

在这里插入图片描述

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



所属网站分类: 技术文章 > 博客

作者:倒车请注意

链接:https://www.pythonheidong.com/blog/article/10426/70c6d9834ed1304589e9/

来源:python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

0 0
收藏该文
已收藏

评论内容:(最多支持255个字符)