繁体   English   中英

尝试使用matplotlib内联进行绘图时,为什么在jupyter笔记本中出现NonGuiException?

[英]Why do I get NonGuiException in jupyter notebook when trying to plot using matplotlib inline?

尝试在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追溯(最近一次调用在)()6列= ['path _ {}'。format(ii)对于ii,范围(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:

%matplotlib inline命令%matplotlib inline 设置后端 检查您是否在其他地方没有设置冲突的后端。

我发现我已经将我的MPLBACKEND环境变量设置为TkAgg 一旦我从pipenv .env文件中删除了该文件并重新启动了Shell和Jupyter笔记本服务器,内联绘图便再次起作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM