Search code examples
pythonplotbokehaxis

Reverse axis in python bokeh


I am trying to reverse the y axis and set range for both x and y in a Bokeh scatter plot. I am using:

BokehPlot.bokeh_scatter(data=df, x_range=(min_utc, max_utc), y_range=(min_val, max_val))

I get an error:

TypeError: bokeh_scatter() got an unexpected keyword argument 'x_range'

Any idea how axes can be reversed in a Bokeh scatterplot with a pandas dataframe input


Solution

  • The following will flip the y-axis for a scatter plot.

    p = figure()
    
    xmin = data[xval].min()
    xmax = data[xval].max()
    ymin = data[yval].min()
    ymax = data[yval].max()
    
    # Note that ymin and ymax are in reverse order in y_range.
    p.scatter(xval, yval, x_range=(xmin, xmax), y_range=(ymax, ymin))
    show(p)