Reverse axis in python bokeh

淺唱寂寞╮ 提交于 2019-12-11 07:33:58

问题


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


回答1:


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) 



回答2:


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.



来源:https://stackoverflow.com/questions/40317898/reverse-axis-in-python-bokeh

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!