3

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

smci
  • 32,567
  • 20
  • 113
  • 146
Don Smythe
  • 9,234
  • 14
  • 62
  • 105
  • 1
    There is no function `bokeh_scatter` in all of the Bokeh library. Are you using some wrapper library around Bokeh? Please provide more information, and more complete code. – bigreddot Oct 29 '16 at 14:47
  • Now I feel pretty dumb, I was calling one of my own classes and methods.. I even had the code to set the range in the method. I'll self answer this – Don Smythe Oct 29 '16 at 14:52
  • It happens to everyone :) – bigreddot Oct 29 '16 at 15:24

2 Answers2

7

If you don't set explicit bounds on your axis, its range will be a DataRange1d, with bounds automatically computed from whatever you plot. In this case, setting the range's flipped attribute will flip it without requiring you to set explicit bounds:

from bokeh.plotting import figure, show
fig = figure()
# Do some plotting calls with fig...
fig.y_range.flipped = True
show(fig)

If you want to set explicit bounds, see this answer on another question. As Don Smythe's answer mentions, you can set the bounds in reverse order to invert any axis type.

Jadrian Miles
  • 121
  • 2
  • 3
5

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) 
Community
  • 1
  • 1
Don Smythe
  • 9,234
  • 14
  • 62
  • 105