org-arl / arlpy

ARL Python Tools
BSD 3-Clause "New" or "Revised" License
119 stars 37 forks source link

Compatibility issues with Bokeh version 3.1.1 #84

Closed patel999jay closed 1 year ago

patel999jay commented 1 year ago

Hello,

I've been using the arlpy toolbox and recently updated Bokeh from version 2.x.x to 3.1.1. After the update, I've encountered some issues with the plotting functions in arlpy.

When running pm.plot_env(env, width=900), I get the following error:

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

This suggests that the attribute 'plot_width' is no longer recognized by the Bokeh Figure object in version 3.1.1. Instead, the 'width' attribute should be used.

When running rays = pm.compute_eigenrays(env , debug=True) and pm.plot_rays(rays, env=env, width=900), I get this error:

ValueError: failed to validate FigureOptions(...).x_range: expected an element of either Instance(Range), Either(Tuple(Float, Float), Tuple(Datetime, Datetime), Tuple(TimeDelta, TimeDelta)), Seq(String), Object(Series) or Object(GroupBy), got None

This error suggests that the 'x_range' attribute of the Bokeh Figure object is not being set correctly in the arlpy plotting functions.

These issues seem to be related to changes in the Bokeh API between version 2.x.x and 3.1.1. To resolve these, the arlpy library would need to be updated to use the new Bokeh API. This would involve updating any instances where Bokeh figures are created or modified in the arlpy code.

Please note that these changes may/could potentially break compatibility with older versions of Bokeh. (not tested yet) Therefore, it might be necessary to implement some sort of version checking to ensure that the correct API is used depending on the installed version of Bokeh.

Here is an example of the required change:

Current code in plot.py:

def _new_figure(title, width, height, xlabel, ylabel, xlim, ylim, xtype, ytype, interactive):
    global _color
    if width is None:
        width = _figsize[0]
    if height is None:
        height = _figsize[1]
    _color = 0
    tools = []
    if interactive is None:
        interactive = _interactive
    if interactive:
        tools = 'pan,box_zoom,wheel_zoom,reset,save'
    f = _bplt.figure(title=title, plot_width=width, plot_height=height, x_range=xlim, y_range=ylim, x_axis_label=xlabel, y_axis_label=ylabel, x_axis_type=xtype, y_axis_type=ytype, tools=tools)
    f.toolbar.logo = None
    return f

should be updated to :

def _new_figure(title, width, height, xlabel, ylabel, xlim, ylim, xtype, ytype, interactive):
    global _color
    if width is None:
        width = _figsize[0]
    if height is None:
        height = _figsize[1]
    _color = 0
    tools = []
    if interactive is None:
        interactive = _interactive
    if interactive:
        tools = 'pan,box_zoom,wheel_zoom,reset,save'
    f = _bplt.figure(title=title, width=width, plot_height=height, x_range=xlim, y_range=ylim, x_axis_label=xlabel, y_axis_label=ylabel, x_axis_type=xtype, y_axis_type=ytype, tools=tools)
    f.toolbar.logo = None
    return f

Please note that other instances where plot_width is used should also be replaced with width. I did not get a chance to look at all instances of the same in repo yet.

mchitre commented 1 year ago

Thanks for the detailed report on what will need to be changed. I'm personally using very little Python nowadays and so have not been following Bokeh updates. Would you be open to making relevant changes and raising a PR @patel999jay ?

patel999jay commented 1 year ago

@mchitre : i reviewed the issue, and created a PR, ready to merge.

bbbrandyn commented 1 year ago

Hi, I also had this issue and also had to change plot_height=height to height=height

Did you have this too @patel999jay ?

mchitre commented 1 year ago

Hi, I also had this issue and also had to change plot_height=height to height=height

Yes, see https://github.com/org-arl/arlpy/blob/acb1b7abc815885f8825d8ca2f1910d44ecd0086/arlpy/plot.py#L61