Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for twin axes in bokeh #1594

Closed
jordansamuels opened this issue Jun 21, 2017 · 3 comments
Closed

Support for twin axes in bokeh #1594

jordansamuels opened this issue Jun 21, 2017 · 3 comments

Comments

@jordansamuels
Copy link
Contributor

jordansamuels commented Jun 21, 2017

There have been several discussions on chat about support for twin axes. @philippjfr generously supplied some examples for matplotlib and for bokeh, but the bokeh one doesn't work. It is below, and with 1.7.0 and 1.8dev2 (with bokeh 0.12.6), it produces a graph which has both left and right y-axes the same.

image

%%opts Curve [toolbar='above']
from bokeh.models import LinearAxis, Range1d

def twinx(plot, element):
    # Setting the second y axis range name and range
    start, end = (element.range(1))
    label = element.dimensions()[1].pprint_label
    plot.state.extra_y_ranges = {"foo": Range1d(start=start, end=end)}
    # Adding the second axis to the plot. 
    linaxis = LinearAxis(axis_label=label, y_range_name='foo')
    plot.state.add_layout(linaxis, 'right')

a = hv.Curve(([1,2], [3,21]), vdims=['A'])
b = hv.Curve(([1,2], [50, -10]), vdims=['B'])(plot=dict(finalize_hooks=[twinx]), style=dict(color='red'))
h = a * b
h.redim.range(x=(0,3))
@iweey
Copy link

iweey commented Sep 10, 2017

image

%%opts Curve  [width=800 height=400 tools=['hover','box_select', 'lasso_select' ] toolbar='above'] 
from bokeh.models import LinearAxis, Range1d

def twinx(plot, element):
    # Setting the second y axis range name and range
    start, end = (element.range(1))
    label = element.dimensions()[1].pprint_label
    plot.state.extra_y_ranges = {"foo": Range1d(start=start, end=end)}
    # Adding the second axis to the plot. 
    linaxis = LinearAxis(axis_label=label, y_range_name='foo')
    plot.state.add_layout(linaxis, 'right')



curve_all = hv.Scatter(ot.drive_pbdf, kdims=['date'], vdims=['speed_kmph'] ) 
curve_all_a = hv.Curve(ot.drive_pbdf, kdims=['date'], vdims=['speed_kmph'] ) 
cc = curve_all*curve_all_a
# curve_all*curve_all_a + curve_acc

curve_acc = hv.Scatter(ot.drive_pbdf, kdims=['date'], vdims=['speed_kmph_acc']) (plot=dict(finalize_hooks=[twinx]), style=dict(color='red'))


# b = hv.Curve(([1,2], [50, -10]), vdims=['B'])(plot=dict(finalize_hooks=[twinx]), style=dict(color='red'))
h =cc * curve_acc
h
# h.redim.range(x=(0,3))

how to set two Y-axis symmetric ?

@bacalfa
Copy link

bacalfa commented Dec 16, 2017

I'm unable to get two y axes with the following code.

%%opts Curve [toolbar='above'] {+framewise}
from bokeh.models import LinearAxis, Range1d

def twinx(plot, element):
    # Setting the second y axis range name and range
    start, end = (element.range(1))
    label = element.dimensions()[1].pprint_label
    plot.state.extra_y_ranges = {"foo": Range1d(start=start, end=end)}
    # Adding the second axis to the plot. 
    linaxis = LinearAxis(axis_label=label, y_range_name='foo')
    plot.state.add_layout(linaxis, 'right')
    
data = dict(A=["A1", "A1", "A2", "A2"], B=["B1", "B1", "B2", "B2"], C=[10, -5, 23, 9], D=[0, 5, -7, 6], E=[2, -5, 8, 5])
df = pd.DataFrame(data=data)

df_hv = hv.Dataset(df)

curve1 = df_hv.to.curve(kdims=["C"], vdims=["D"], groupby=["A", "B"])
curve2 = df_hv.to.curve(kdims=["C"], vdims=["E"], groupby=["A", "B"]).opts(plot=dict(finalize_hooks=[twinx]), style=dict(color='red'))
curve1 * curve2

Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 23, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

5 participants