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
MUMU2399
V2EX  ›  Python

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

  •  
  •   MUMU2399 · 2023-03-17 11:00:48 +08:00 · 1246 次点击
    这是一个创建于 377 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

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

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

    import matplotlib as mpl
    mpl.use('Agg')
    mrtctl
        6
    mrtctl  
       2023-03-18 12:38:12 +08:00
    然后关于保存其他格式,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
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   5286 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 46ms · UTC 09:35 · PVG 17:35 · LAX 02:35 · JFK 05:35
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.