amaiya/ktrain

Topic Modeling Visualization is not working with bokeh 3.x.x

Closed this issue · 3 comments

tm.visualize_documents(doc_topics=tm.get_doctopics()) throws an error "AttributeError: unexpected attribute 'plot_width' to figure, similar attributes are outer_width, width or min_width"

From bokeh 2.x.x. documentation:
plot_width | This is a compatibility alias for the width property
plot_height | This is a compatibility alias for the height property

It appears plot_width and plot_height are no longer available in bokeh 3 and the visualization code must be updated to accommodate the change: plot_width is now width and plot_height is now height.

tm.visualize_documents(doc_topics=tm.get_doctopics())

AttributeError Traceback (most recent call last)
Cell In[19], line 1
----> 1 tm.visualize_documents(doc_topics=tm.get_doctopics())

File /opt/conda/lib/python3.10/site-packages/ktrain/text/eda.py:598, in TopicModel.visualize_documents(self, texts, doc_topics, width, height, point_size, title, extra_info, colors, filepath)
596 source = bp.ColumnDataSource(data=dct)
597 hover = HoverTool(tooltips=tool_tups)
--> 598 p = bp.figure(
599 plot_width=width,
600 plot_height=height,
601 tools=[hover, "save", "pan", "wheel_zoom", "box_zoom", "reset"],
602 # tools="pan,wheel_zoom,box_zoom,reset,hover,previewsave",
603 title=title,
604 )
605 # plot_lda = bp.figure(plot_width=1400, plot_height=1100,
606 # title=title,
607 # tools="pan,wheel_zoom,box_zoom,reset,hover,previewsave",
608 # x_axis_type=None, y_axis_type=None, min_border=1)
609 p.circle("x", "y", size=point_size, source=source, fill_color="fill_color")

File /opt/conda/lib/python3.10/site-packages/bokeh/plotting/_figure.py:192, in figure.init(self, *arg, **kw)
190 for name in kw.keys():
191 if name not in names:
--> 192 self._raise_attribute_error_with_matches(name, names | opts.properties())
194 super().init(*arg, **kw)
196 self.x_range = get_range(opts.x_range)

File /opt/conda/lib/python3.10/site-packages/bokeh/core/has_props.py:368, in HasProps._raise_attribute_error_with_matches(self, name, properties)
365 if not matches:
366 matches, text = sorted(properties), "possible"
--> 368 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

A simple fix to the issue is to modify, eda.py as follows:
from:
p = bp.figure(
plot_width=width,
plot_height=height,

to:
p = bp.figure(
width=width,
height=height,

amaiya commented

Thank you for not only opening the issue but letting me know the fix! This will be included in next release.