【发布时间】:2017-03-19 07:50:15
【问题描述】:
当我尝试在我的笔记本中绘制数据框时,我看到一个“非 gui”异常被抛出。
import pandas as pd
import sys,os
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline
%pylab inline
ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
df = pd.DataFrame(np.random.randn(1000, 4), index=ts.index, columns=list('ABCD'))
df = df.cumsum()
plt.figure(); df.plot(); #<-- Exception here
显示了一个绘图,绘制了df 的第一列,然后我看到了这个异常。当我尝试绘制一个系列时,我没有看到任何问题。这是异常跟踪:
(看起来我们正在尝试将 df 绘制为“交互式”图,是否有任何其他函数/参数可以尝试不“交互式”)
...\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in __call__(self, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
...\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in plot_frame(data, x, y, kind, ax, subplots, sharex, sharey, layout, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, secondary_y, sort_columns, **kwds)
...\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in _plot(data, x, y, subplots, ax, kind, **kwds)
...\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in generate(self)
...\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in _make_plot(self)
...\Anaconda2\lib\site-packages\pandas\tools\plotting.pyc in _ts_plot(cls, ax, x, data, style, **kwds)
...\Anaconda2\lib\site-packages\pandas\tseries\plotting.pyc in format_dateaxis(subplot, freq)
...\Anaconda2\lib\site-packages\IPython\utils\decorators.pyc in wrapper(*args, **kw)
...\Anaconda2\lib\site-packages\matplotlib\backends\backend_tkagg.pyc in draw_if_interactive()
68 figManager = Gcf.get_active()
69 if figManager is not None:
---> 70 figManager.show()
71
72 class Show(ShowBase):
...\Anaconda2\lib\site-packages\matplotlib\backend_bases.pyc in show(self)
2618 optional warning.
2619 """
-> 2620 raise NonGuiException()
2621
2622 def destroy(self):
NonGuiException:
【问题讨论】:
-
您的代码对我有用。这似乎是一个配置问题。您能否发布有关您的平台、您使用的 python 解释器以及所涉及的包的版本的详细信息?
标签: python python-2.7 pandas matplotlib