推荐学习书目
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
MUMU2399
V2EX  ›  Python

请问我 Mac 用 pycharm 运行绘图程序 plt 之后为什么总是多出来 Python 图标,如图所示

  •  
  •   MUMU2399 · Mar 17, 2023 · 2353 views
    This topic created in 1154 days ago, the information mentioned may be changed or developed.

    [如图所示]( https://raw.githubusercontent.com/Mu2399/personalimagehost/master/uPic/截屏 2023-03-17 10.54.15.png)

    而且我没有找到图片另存为其他格式的选项。。。 求大佬指导

    6 replies    2023-03-18 12:38:12 +08:00
    MUMU2399
        1
    MUMU2399  
    OP
       Mar 17, 2023
    redh
        3
    redh  
       Mar 17, 2023
    LIBQ
        4
    LIBQ  
       Mar 17, 2023
    没见过 等大佬
    mrtctl
        5
    mrtctl  
       Mar 18, 2023
    matplotlib 在 Mac 上默认用的应该是一个带 GUI (绘图窗口)的 backend 。然后 Mac 上要渲染窗口是要在 Dock 栏上有图标才行。如果你不需要交互式的绘图窗口的话(比如 plot 完只是 savefig 就行,不需要 fig.show() 之类的),可以换成一个没有 GUI 的 backend ,比如 agg:

    import matplotlib as mpl
    mpl.use('Agg')
    mrtctl
        6
    mrtctl  
       Mar 18, 2023
    然后关于保存其他格式,savefig 是会自动靠后缀名检测格式的。比如:

    fig.savefig("fig.png", dpi=300, transparent=True)
    fig.savefig("fig.jpg", dpi=300)
    fig.savefig("fig.pdf")

    具体可以看文档: https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.savefig.html
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   5888 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 37ms · UTC 03:25 · PVG 11:25 · LAX 20:25 · JFK 23:25
    ♥ Do have faith in what you're doing.