Correct Syntax for autosizing DataRange1d against a column source?

I’m trying to setup a chart with two y axes, and I’m having trouble with the axis ranges.

pandas data frame; column are ‘x’, ‘y1’, ‘y2’

cds = ColumnDataSource(pd.df)

setup the plot

p = figure(…)

add the right y-axis

p.extra_y_ranges[‘y2axis’] = Range1d(start=0, end=100)
p.add_layout(LinearAxis(y_range_name=‘y2axis’), ‘right’)

add the line glyphs

p.line(x=x,y=y1, source=cds)
p.line(x=x,y=y2, source=cds, y_range_name=‘y2axis’)

what’s the correct syntax for autosetting the ‘y’ axis range from just the ‘y1’ column?

this used to be correct prior to 0.9 release, but 'sources" has been removed as an argument.

p.y_range = DataRange1d(sources=[cds.columns(‘y1’)])

``

The y_range is getting calculated by a union of the y1 and y2 data columns. I.e., y1 has data from 0-50; y2 has data from 35-100; the union is 0-100 shown on both axes. If I remove the y2 line, then I get the correct range (0-50) on the left axis.

Thanks,

Jeff

Jeff,

DataRange1d no longer has a "columns" property (probably for more than a year now). Instead of doing a simple envelope over column data, data ranges now ask individual renderers for their preferred bounds (this way auto ranging works correctly takes the "extent" of glyphs into account, which a naive envelope over the coordinates does not). By default the DataRange1d looks at all available renderers, but you can configure a specific set of renderers with the "renderers" property, described here:

  http://bokeh.pydata.org/en/latest/docs/reference/models/ranges.html#bokeh.models.ranges.DataRange.renderers

In 0.10 glyph methods were made to return the renderers they create, so it is easy to configure the renderer you want:

  # pandas data frame; column are 'x', 'y1', 'y2'
  cds = ColumnDataSource(pd.df)

  # setup the plot
  p = figure(...)

  # add the right y-axis
  p.extra_y_ranges['y2axis'] = Range1d(start=0, end=100)
  p.add_layout(LinearAxis(y_range_name='y2axis'), 'right')
  
  # add the line glyphs, save their renderers
  y1 = p.line(x=x,y=y1, source=cds)
  y2 = p.line(x=x,y=y2, source=cds, y_range_name='y2axis')

  # this is the new part
  p.y_range.renderers=[y1]

Bryan

···

On Dec 9, 2015, at 12:30 PM, Jeff Harris <[email protected]> wrote:

I'm trying to setup a chart with two y axes, and I'm having trouble with the axis ranges.

# pandas data frame; column are 'x', 'y1', 'y2'
cds = ColumnDataSource(pd.df)

# setup the plot
p = figure(...)

# add the right y-axis
p.extra_y_ranges['y2axis'] = Range1d(start=0, end=100)
p.add_layout(LinearAxis(y_range_name='y2axis'), 'right')

# add the line glyphs
p.line(x=x,y=y1, source=cds)
p.line(x=x,y=y2, source=cds, y_range_name='y2axis')

# what's the correct syntax for autosetting the 'y' axis range from just the 'y1' column?
# this used to be correct prior to 0.9 release, but 'sources" has been removed as an argument.
p.y_range = DataRange1d(sources=[cds.columns('y1')])

The y_range is getting calculated by a union of the y1 and y2 data columns. I.e., y1 has data from 0-50; y2 has data from 35-100; the union is 0-100 shown on both axes. If I remove the y2 line, then I get the correct range (0-50) on the left axis.

Thanks,
Jeff

--
You received this message because you are subscribed to the Google Groups "Bokeh Discussion - Public" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/ba434337-96fb-44c2-aa9e-86125b6ac126%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.