4

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

3
  • 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. Commented Oct 29, 2016 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 Commented Oct 29, 2016 at 14:52
  • It happens to everyone :) Commented Oct 29, 2016 at 15:24

2 Answers 2

8

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.

Sign up to request clarification or add additional context in comments.

Comments

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) 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.