相关疑难解决方法(0)

如何在Python中设置matplotlib中的"后端"?

我是matplotlib的新用户,我的平台是Ubuntu 10.04 Python 2.6.5

这是我的代码

import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt 
plt.plot([1,2,3])
Run Code Online (Sandbox Code Playgroud)

错误是:

/usr/local/lib/python2.6/dist-packages/matplotlib/backends/__init__.py:41: UserWarning: 
Your currently selected backend, 'agg' does not support show().
Please select a GUI backend in your matplotlibrc file ('/usr/local/lib/python2.6/dist-packages/matplotlib/mpl-data/matplotlibrc')
or with matplotlib.use()
  (backend, matplotlib.matplotlib_fname()))
Run Code Online (Sandbox Code Playgroud)
  • 我安装了Anti-Grain Geometry库,apt-get install libagg但它不起作用.
  • 我尝试使用后端的其他参数,如'GTK'和'TkAgg'.
  • 我安装了python-gtk2-dev包,但仍然出现错误.
  • 谁能告诉我一个可执行的后端参数及其依赖库?

这是错误:

>>> matplotlib.use('GTK')
>>> import matplotlib.pyplot as plt
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/lib/python2.6/dist-packages/matplotlib/pyplot.py", line 95, in <module>
    new_figure_manager, draw_if_interactive, show = …
Run Code Online (Sandbox Code Playgroud)

python linux graphics matplotlib

74
推荐指数
6
解决办法
14万
查看次数

当我在jupyter笔记本中使用matplotlib时,它总是引发"matplotlib目前正在使用非GUI后端"错误?

import matplotlib.pyplot as pl
%matplot inline
def learning_curves(X_train, y_train, X_test, y_test):
""" Calculates the performance of several models with varying sizes of training data.
    The learning and testing error rates for each model are then plotted. """

print ("Creating learning curve graphs for max_depths of 1, 3, 6, and 10. . .")

# Create the figure window
fig = pl.figure(figsize=(10,8))

# We will vary the training set size so that we have 50 different sizes
sizes = np.rint(np.linspace(1, len(X_train), 50)).astype(int) …
Run Code Online (Sandbox Code Playgroud)

python matplotlib jupyter-notebook

36
推荐指数
8
解决办法
6万
查看次数

标签 统计

matplotlib ×2

python ×2

graphics ×1

jupyter-notebook ×1

linux ×1