V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
lynn0977
V2EX  ›  Python

matplotlib 画的图怎么自适应窗口大小

  •  
  •   lynn0977 · 2020-08-20 17:45:28 +08:00 · 4951 次点击
    这是一个创建于 1338 天前的主题,其中的信息可能已经有所发展或是发生改变。
    使用 fig = Figure(figsize=(10,16))的方式创建一个图像,当 pyQt 的窗口大小变化时,matplotlib 的图形(以及画图区域)是始终固定不变的,请教一下是否有办法让画图区域和图像大小随窗口大小变化?
    4 条回复    2020-08-21 22:07:21 +08:00
    volvo007
        1
    volvo007  
       2020-08-20 22:01:02 +08:00
    是默认的 plt.show() 给的界面吗? 好像不限定 figsize 的话就可以自适应了?
    lynn0977
        2
    lynn0977  
    OP
       2020-08-20 23:12:37 +08:00 via Android
    @volvo007 是 pyqt 的窗口
    AmberJiang
        3
    AmberJiang  
       2020-08-21 13:23:48 +08:00
    你可以试试 fig.set_size_inches(new_size, new_size, forward=True)方法
    不行的话,你可以试试这个答主提供的自定义 widget 的方法在 pyQt 里面:
    https://stackoverflow.com/questions/44505229/pyqt-automatically-resizing-widget-picture
    necomancer
        4
    necomancer  
       2020-08-21 22:07:21 +08:00
    fig.set_tight_layout(True)
    或者 plt.tight_layout()
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   1792 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 24ms · UTC 16:26 · PVG 00:26 · LAX 09:26 · JFK 12:26
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.