gpt4 book ai didi

python - Matplotlib:删除有关 matplotlib.use() 的警告

转载 作者:太空狗 更新时间:2023-10-29 21:43:42 29 4
gpt4 key购买 nike

在我使用 matplotlib 的 Python 模块中,当我通过 ssh 在远程机器上运行脚本时,我想确保它也能正常工作。所以我这样做:

import matplotlib
matplotlib.use('Agg')
from matplotlib.backends.backend_pdf import PdfPages
import matplotlib.mlab as mlab
import matplotlib.pyplot as plt
import numpy as np
import pylab
import scipy.stats
import scipy.stats.mstats

它有效。太糟糕了,当我在机器上直接运行它时(不是远程机器!),它会给我以下警告:

This call to matplotlib.use() has no effect because the the backend has already been chosen; matplotlib.use() must be called before pylab, matplotlib.pyplot, or matplotlib.backends is imported for the first time.

如何删除此消息?

最佳答案

虽然我无法测试这个 Ipython 告诉我“可以设置 warn=False 来支持警告。”

来源:

matplotlib.use?

Type: function
String Form:<function use at 0x98da02c>
File: /usr/lib/pymodules/python2.7/matplotlib/__init__.py
Definition: matplotlib.use(arg, warn=True)
Docstring:
Set the matplotlib backend to one of the known backends.

The argument is case-insensitive. For the Cairo backend,
the argument can have an extension to indicate the type of
output. Example:

use('cairo.pdf')

will specify a default of pdf output generated by Cairo.

.. note::

This function must be called *before* importing pyplot for
the first time; or, if you are not using pyplot, it must be called
before importing matplotlib.backends. If warn is True, a warning
is issued if you try and call this after pylab or pyplot have been
loaded. In certain black magic use cases, e.g.
:func:`pyplot.switch_backends`, we are doing the reloading necessary to
make the backend switch work (in some cases, e.g. pure image
backends) so one can set warn=False to supporess the warnings.

To find out which backend is currently set, see
:func:`matplotlib.get_backend`.

在文档中发现拼写错误总是很有趣。

关于python - Matplotlib:删除有关 matplotlib.use() 的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16170989/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com