尝试在jupyter笔记本中插入内联时出错。
%matplotlib inline
N = 20
M = 10
df = pd.DataFrame(
index=pd.date_range(dtt.date.today(), periods=N),
data=np.random.randn(N, M),
columns=['path_{}'.format(ii) for ii in range(M)]
)
df.plot()
我收到以下NonGuiException
错误。即使图像绘制它似乎引发了异常。如果作为数据帧的索引,我使用range(N)
它就可以正常工作,这很奇怪。
任何想法是怎么回事? -------------------------------------------------- ------------------------- NonGuiException Traceback(最近一次调用last)in() 6列= ['路径_ {}' .format(ii)for ii in range(M)] 7) ----> 8 df.plot()
/usr/local/lib/python3.5/dist-packages/pandas/tools/plotting.py 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) 3771 fontsize=fontsize, colormap=colormap, table=table, 3772 yerr=yerr, xerr=xerr, secondary_y=secondary_y,
-> 3773 sort_columns=sort_columns, **kwds) 3774 __call__.__doc__ = plot_frame.__doc__ 3775
/usr/local/lib/python3.5/dist-packages/pandas/tools/plotting.py 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) 2640 yerr=yerr, xerr=xerr, 2641 secondary_y=secondary_y, sort_columns=sort_columns,
-> 2642 **kwds) 2643 2644
/usr/local/lib/python3.5/dist-packages/pandas/tools/plotting.py in
_plot(data, x, y, subplots, ax, kind, **kwds) 2467 plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds) 2468
-> 2469 plot_obj.generate() 2470 plot_obj.draw() 2471 return plot_obj.result
/usr/local/lib/python3.5/dist-packages/pandas/tools/plotting.py in generate(self) 1041 self._compute_plot_data() 1042 self._setup_subplots()
-> 1043 self._make_plot() 1044 self._add_table() 1045 self._make_legend()
/usr/local/lib/python3.5/dist-packages/pandas/tools/plotting.py in
_make_plot(self) 1724 stacking_id=stacking_id, 1725 is_errorbar=is_errorbar,
-> 1726 **kwds) 1727 self._add_legend_handle(newlines[0], label, index=i) 1728
/usr/local/lib/python3.5/dist-packages/pandas/tools/plotting.py in
_ts_plot(cls, ax, x, data, style, **kwds) 1764 lines = cls._plot(ax, data.index, data.values, style=style, **kwds) 1765
# set date formatter, locators and rescale limits
-> 1766 format_dateaxis(ax, ax.freq) 1767 return lines 1768
/usr/local/lib/python3.5/dist-packages/pandas/tseries/plotting.py in format_dateaxis(subplot, freq)
292 "t = {0} y = {1:8f}".format(Period(ordinal=int(t), freq=freq), y))
293
--> 294 pylab.draw_if_interactive()
/usr/local/lib/python3.5/dist-packages/IPython/utils/decorators.py in wrapper(*args, **kw)
41 def wrapper(*args,**kw):
42 wrapper.called = False
---> 43 out = func(*args,**kw)
44 wrapper.called = True
45 return out
/usr/lib/python3/dist-packages/matplotlib/backends/backend_tkagg.py in draw_if_interactive()
68 figManager = Gcf.get_active()
69 if figManager is not None:
---> 70 figManager.show()
71
72 class Show(ShowBase):
/usr/lib/python3/dist-packages/matplotlib/backend_bases.py in show(self) 2618 optional warning. 2619 """
-> 2620 raise NonGuiException() 2621 2622 def destroy(self):
NonGuiException:
答案 0 :(得分:0)
命令%matplotlib inline
sets the backend。检查您是否没有设置有冲突的后端somewhere else。
我发现我将MPLBACKEND
环境变量设置为TkAgg
。一旦我从pipenv
.env
文件中删除了该文件并重新启动了Shell和Jupyter笔记本服务器,内联绘图便再次起作用。