Reputation: 9814
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
Upvotes: 4
Views: 8227
Reputation: 130
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.
Upvotes: 8
Reputation: 9814
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)
Upvotes: 5