8

私が使用している 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

できます。残念なことに、マシン(リモートマシンではありません!)で直接実行すると、次の警告が表示されます。

バックエンドが既に選択されているため、この matplotlib.use() の呼び出しは効果がありません。 pylab、matplotlib.pyplot、または matplotlib.backends を初めてインポートする前に、 matplotlib.use() を呼び出す必要があります。

このメッセージを削除するにはどうすればよいですか?

4

2 に答える 2

5

この Ipython をテストすることはできませんが、「警告をサポートするために warn=False を設定できます」と Ipython は教えてくれます。

ソース:

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`.

ドキュメントのタイプミスを見つけるのはいつも楽しいです。

于 2013-04-23T14:11:40.753 に答える