在我使用的Python模块中matplotlib
,我想确保当我通过以下方式在远程计算机上运行脚本时它也能工作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
有用。太糟糕了,当我运行它时directly在机器上(不是远程的!),它给了我以下警告:
对 matplotlib.use() 的调用没有效果,因为后端
已经被选择了;必须调用 matplotlib.use()before导入 pylab、matplotlib.pyplot 或 matplotlib.backends
第一次。
如何删除此消息?
虽然我无法测试这个,但 Ipython 告诉我“可以设置 warn=False 来支持警告”。
Source:
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`.
在文档中发现拼写错误总是很有趣。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)