PatrikHlobil / Pandas-Bokeh

Bokeh Plotting Backend for Pandas and GeoPandas

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

[Bug] AttributeError: unexpected attribute 'plot_width'

elhele opened this issue · comments

Hello,

plot_bokeh worked for me last week, but it seems that there were some updates in pandas or somewhere else and it stopped working. This code from the example (or any other)

import numpy as np

np.random.seed(42)
df = pd.DataFrame({"Google": np.random.randn(1000)+0.2, 
                   "Apple": np.random.randn(1000)+0.17}, 
                   index=pd.date_range('1/1/2000', periods=1000))
df = df.cumsum()
df = df + 50
df.plot_bokeh(kind="line", plot_width=None) 

produces the following error:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
Input In [45], in <cell line: 9>()
      7 df = df.cumsum()
      8 df = df + 50
----> 9 df.plot_bokeh(kind="line", plot_width=None)

File /opt/conda/lib/python3.10/site-packages/pandas_bokeh/plot.py:1785, in FramePlotMethods.__call__(self, *args, **kwargs)
   1784 def __call__(self, *args, **kwargs):
-> 1785     return plot(self.df, *args, **kwargs)

File /opt/conda/lib/python3.10/site-packages/pandas_bokeh/plot.py:439, in plot(df_in, x, y, kind, figsize, use_index, title, legend, logx, logy, xlabel, ylabel, xticks, yticks, xlim, ylim, fontsize_title, fontsize_label, fontsize_ticks, fontsize_legend, color, colormap, category, histogram_type, stacked, weights, bins, normed, cumulative, show_average, plot_data_points, plot_data_points_size, number_format, disable_scientific_axes, show_figure, return_html, panning, zooming, sizing_mode, toolbar_location, hovertool, hovertool_string, rangetool, vertical_xlabel, x_axis_location, webgl, reuse_plot, **kwargs)
    432     xlabelname = (
    433         figure_options["x_axis_label"]
    434         if figure_options.get("x_axis_label", "") != ""
    435         else "x"
    436     )
    438 # Create Figure for plotting:
--> 439 p = figure(**figure_options)
    440 if "x_axis_type" not in figure_options:
    441     figure_options["x_axis_type"] = None

File /opt/conda/lib/python3.10/site-packages/bokeh/plotting/_figure.py:184, in figure.__init__(self, *arg, **kw)
    182 for name in kw.keys():
    183     if name not in names:
--> 184         self._raise_attribute_error_with_matches(name, names | opts.properties())
    186 super().__init__(*arg, **kw)
    188 self.x_range = get_range(opts.x_range)

File /opt/conda/lib/python3.10/site-packages/bokeh/core/has_props.py:369, in HasProps._raise_attribute_error_with_matches(self, name, properties)
    366 if not matches:
    367     matches, text = sorted(properties), "possible"
--> 369 raise AttributeError(f"unexpected attribute {name!r} to {self.__class__.__name__}, {text} attributes are {nice_join(matches)}")

AttributeError: unexpected attribute 'plot_width' to figure, similar attributes are outer_width, width or min_width

I use Python 3.10 in Jupyter Notebooks, pandas_bokeh installed with pip.

It seems that other people started having the same problem quite recently:

https://stackoverflow.com/questions/74280959/attributeerror-unexpected-attribute-plot-width-to-figure-similar-attributes

I've run into this issue as well. It seems Bokeh deprecated plot_width and plot_height, so Pandas-Bokeh will need to be updated accordingly, see bokeh/bokeh#12543

This looks like it was fixed by e6452b3.

@PatrikHlobil Is there any chance you could release a new version with this fix to make it easier to pull in via pip or other package managers?

commented

This looks like it was fixed by e6452b3.

@PatrikHlobil Is there any chance you could release a new version with this fix to make it easier to pull in via pip or other package managers?

Please

Hi there, sorry I do not have a lot of time maintaining this library. I will have a look at the problem and hope that I can soon release a fix.

Hi there, sorry I do not have a lot of time maintaining this library. I will have a look at the problem and hope that I can soon release a fix.

For what its worth, I have been running commit e71bb52 locally (this is the latest commit I see in your repo) for a few weeks now and it is working well, so this may not need more than creating a new release with the existing code.

Any release for this bug anytime soon? ;) Thank you for your work!

commented

Hi I find a temporary fix in stackoverflow https://stackoverflow.com/a/75149903/5614835 stackoverflow and it works

try it out.

go to : ./lib/python3.10/site-packages/pandas_bokeh/plot.py"

add these before line 439, in plot.py

figure_options['width'] = figure_options['plot_width']
figure_options['height'] = figure_options['plot_height']
del figure_options['plot_width']
del figure_options['plot_height']

I'm using virtual env so these are the steps I followed:
image
image
image
image