Pandas: dataframe plot method throws an error

Created on 22 Jan 2018  Â·  13Comments  Â·  Source: pandas-dev/pandas

Code Sample, a copy-pastable example if possible

import pandas as pd
import numpy as np
import matplotlib
import matplotlib.pyplot as plt

ts = pd.Series(np.random.randn(1000), index=pd.date_range('1/1/2000', periods=1000))
ts = ts.cumsum()
ts.plot()

Problem description

Getting an error:

NameError: name '_converter' is not defined

https://stackoverflow.com/questions/48341233/ts-plot-and-dataframe-plot-throwing-error-nameerror-name-converter-is

Expected Output

chart as usual

Output of pd.show_versions()

INSTALLED VERSIONS

commit: None
python: 3.6.2.final.0
python-bits: 64
OS: Linux
OS-release: 4.9.75-25.55.amzn1.x86_64
machine: x86_64
processor:
byteorder: little
LC_ALL: C.UTF-8
LANG: C.UTF-8
LOCALE: en_US.UTF-8

pandas: 0.22.0
pytest: 3.3.2
pip: 9.0.1
setuptools: 36.5.0.post20170921
Cython: 0.27.3
numpy: 1.13.3
scipy: None
pyarrow: None
xarray: None
IPython: 6.2.1
sphinx: None
patsy: None
dateutil: 2.6.1
pytz: 2017.3
blosc: None
bottleneck: None
tables: None
numexpr: None
feather: None
matplotlib: 2.1.2
openpyxl: 2.4.9
xlrd: None
xlwt: None
xlsxwriter: None
lxml: 4.1.1
bs4: 4.6.0
html5lib: 1.0.1
sqlalchemy: 1.2.1
pymysql: 0.8.0
psycopg2: None
jinja2: 2.10
s3fs: None
fastparquet: 0.1.3
pandas_gbq: None
pandas_datareader: None

Usage Question Visualization

Most helpful comment

After restarting server (docker container in my case) plot method worked as expected.

All 13 comments

---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
<ipython-input-61-c6f8bd02937c> in <module>()
      7 ts = ts.cumsum()
      8 
----> 9 ts.asfreq('D').plot();
     10 plt.show()

/opt/conda/lib/python3.6/site-packages/pandas/plotting/_core.py in __call__(self, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
   2501                            colormap=colormap, table=table, yerr=yerr,
   2502                            xerr=xerr, label=label, secondary_y=secondary_y,
-> 2503                            **kwds)
   2504     __call__.__doc__ = plot_series.__doc__
   2505 

/opt/conda/lib/python3.6/site-packages/pandas/plotting/_core.py in plot_series(data, kind, ax, figsize, use_index, title, grid, legend, style, logx, logy, loglog, xticks, yticks, xlim, ylim, rot, fontsize, colormap, table, yerr, xerr, label, secondary_y, **kwds)
   1925                  yerr=yerr, xerr=xerr,
   1926                  label=label, secondary_y=secondary_y,
-> 1927                  **kwds)
   1928 
   1929 

/opt/conda/lib/python3.6/site-packages/pandas/plotting/_core.py in _plot(data, x, y, subplots, ax, kind, **kwds)
   1725                             pass
   1726                 data = series
-> 1727         plot_obj = klass(data, subplots=subplots, ax=ax, kind=kind, **kwds)
   1728 
   1729     plot_obj.generate()

/opt/conda/lib/python3.6/site-packages/pandas/plotting/_core.py in __init__(self, data, **kwargs)
    929 
    930     def __init__(self, data, **kwargs):
--> 931         MPLPlot.__init__(self, data, **kwargs)
    932         if self.stacked:
    933             self.data = self.data.fillna(value=0)

/opt/conda/lib/python3.6/site-packages/pandas/plotting/_core.py in __init__(self, data, kind, by, subplots, sharex, sharey, use_index, figsize, grid, legend, rot, ax, fig, title, xlim, ylim, xticks, yticks, sort_columns, fontsize, secondary_y, colormap, table, layout, **kwds)
     98                  table=False, layout=None, **kwds):
     99 
--> 100         _converter._WARN = False
    101         self.data = data
    102         self.by = by

NameError: name '_converter' is not defined


Try this:

from pandas.plotting._misc import (scatter_matrix, radviz,
                                   andrews_curves, bootstrap_plot,
                                   parallel_coordinates, lag_plot,
                                   autocorrelation_plot)
from pandas.plotting._core import boxplot
from pandas.plotting._style import plot_params
from pandas.plotting._tools import table

from pandas.plotting._converter import \
    register as register_matplotlib_converters
from pandas.plotting._converter import \
    deregister as deregister_matplotlib_converters

and let me know if any of those imports fail.

None of the imports fail. And still getting the same error as mentioned above.

Can you reproduce this in a fresh environment?

After restarting server (docker container in my case) plot method worked as expected.

I had the same error, but after installing matplotlib and scipy it solved itself. I guess those deps should be checked in a nicer way?

@bjourne so you you ran the above code (top of PR) and it didn't raise on the import matplotlib when it was not installed?

I never ran the same code, but I had the same error. In my case, it was triggered by an call to df.plot.kde() where df was a pandas.DataFrame.

I ran into the same error, thrown at dataframe.hist(), installing scipy and matplotlib didn't seem to do the trick (or I did it wrong?)

@ikari-pl Can you run the code in the top post? Do you then also get this error?

I had the same error as above. After installing scipy AND restarting jupyter notebook plotting worked for me. I think restarting the notebook has to happen.

That's true in general. Python doesn't handle dynamically reloading modules
well.

On Thu, Feb 15, 2018 at 12:14 PM, Paul Singman notifications@github.com
wrote:

I had the same error as above. After installing scipy AND restarting
jupyter notebook plotting worked for me. I think restarting the notebook
has to happen.

—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
https://github.com/pandas-dev/pandas/issues/19340#issuecomment-366014345,
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABQHIp1EOvHyXNxYk7vVfl7mM-aJh_Owks5tVHQKgaJpZM4RmPJr
.

UNINSTALL PANDAS
UNINSTALL MATPLOTLIB
INSTALL PANDAS
INSTALL MATPLOTLIB
RESTART JUPYTER

Was this page helpful?
0 / 5 - 0 ratings