简体   繁体   中英

Bokeh auto-scaling axes, after adding secondary y-axis

I am trying to plot two sets of graphs on one figure with a secondary y-axis. I can't get both of them to do auto-scaling according to the data.

I can't set the ranges because I am tabbing 10 figures and the code will be used for different sources whose ranges will vary. Also, currently, I have one range set to specific values but I would like to have them both set to auto-scaling.

The dataframe looks like:

Wavelength 340 440 550 ... 340std 440std 2017-07-01 14:40 2.05 3.02 2.14 ... 0.002 0.00054 ....


TOOLS = "pan,wheel_zoom,box_zoom,reset,save"
p = figure(tools=TOOLS, x_axis_type='datetime',plot_height=400, 
           plot_width=700,
           outline_line_color = 'gray',
           y_axis_label = 'Radiance[W/m^2.sr.nm]',
           y_range = DataRange1d()
          )
# Setting the second y axis range name and range
p.extra_y_ranges = {"foo": Range1d(start=0, end=0.000006)}

# Adding the second axis to the plot.  
p.add_layout(LinearAxis(y_range_name="foo"), 'right')

p.line(x='Time', y='340.0', line_color="darkcyan", line_width=1, 
       source=source)
p.line(x='Time',y='340.0std', line_color = 'red', line_width=1, 
       y_range_name="foo", source=source)

one = Panel(child=row(p), title='wavelength_one')
tabs = Tabs(tabs = [one,two,three,four,five,six])

show(tabs)

The current output looks as follows: 输出截图

A few things should be noted:

  • If you supply explicit range values, either by using a fixed Range1d or by manually setting start or end on a DataRange1d then Bokeh assumes you are doing that on purpose, and won't override your settings (ie no data-ranging anymore)

  • Just FYI, since it is not clear what you are after, Bokeh "twin" axes will always maintain their original relative scale to one another. The cannot vary independently once initialized. (eg zooming one will zoom the other by the same proportion)

  • DataRange1d objects have a renderers property that you can specify, to explicitly tell the range which glyphs to consider when auto-ranging. By default DataRange1d automatically try to consider every available glyph, unless you tell it otherwise:

     r1 = p.line(...) p.y_range.renderers = [r1] # only auto-range based on this one line 
  • I'm not sure it will work to have two auto-ranges with twin axes. AFAIK no one has ever tried. You may only be able to set auto-ranging by configuring the main range DataRange1d with one of the glyphs, and an initial fixed range Range1d on the extra (that will scale as the other main range scales)

I am working also with data streaming with bokeh. I had the same problem, and I have been searching for a solution. I have just tried a new thing, which helped me to solve this problem. Try this: Instead of putting y_range = DataRange1d() , just set None value to y_range = None . For every callback it should be same I think. I hope this helps you to solve this problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM