I get an error when trying to plot inline in a jupyter notebook.
%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()
I get the following NonGuiException
error. Even though the image plots it seems to raise an exception. If as the index to the dataframe I use range(N)
it works just fine which is strange.
Any ideas what is going on? --------------------------------------------------------------------------- NonGuiException Traceback (most recent call last) in () 6 columns=['path_{}'.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:
The command %matplotlib inline
sets the backend . Check you haven't set a conflicting backend somewhere else .
I found that I had set my MPLBACKEND
environment variable to TkAgg
. As soon as I deleted it from my pipenv
.env
file and restarted my shell and Jupyter notebook server, inline ploting worked again.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.