Skip to content

fixedrange=True is not always maintained #508

Closed
@pfbuxton

Description

@pfbuxton

The following has the correct behaviour, if you zoom in and then double-click to zoom out the yaxis2 does not change:

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go

app = dash.Dash(__name__)

trace1 = go.Scatter(
    x=[1, 2, 3, 4],
    y=[1, 2, 3, 4],
    xaxis='x1',
    yaxis='y'
)
trace2 = go.Scatter(
    x=[1, 2, 3, 4],
    y=[0.2, 999, 0.3, 0.4],
    xaxis='x1',
    yaxis='y2'
)

# Layout
layout = dict(
    xaxis = dict(
        title='xaxis',
        range=[0, 4],
    ),
    yaxis = dict(
        title='yaxis',
        range=[-1, 5]
    ),
    yaxis2=dict(
        title='yaxis2',
        titlefont=dict(
            color='#229954'
        ),
        tickfont=dict(
            color='#229954'
        ),
        overlaying='y',
        side='right',
        showgrid=False,
        zeroline=False,
        range=[-1, 1],
        fixedrange=True
    ),
)

data = [ trace1, trace2 ]

figure = dict(
    data=data,
    layout=layout
)

app.layout = html.Div(children=[
    html.H1(children='yaxis2 stays fixed'),
    
    dcc.Graph(
        id='example-graph',
        figure=figure
    )
])


if __name__ == '__main__':
    app.run_server(debug=True)

However, the when we run the following, CLICK, zoom in and double-click to zoom out the yaxis2 is auto-scaled:

import dash
import dash_core_components as dcc
import dash_html_components as html
import plotly.graph_objs as go

app = dash.Dash(__name__)

trace1 = go.Scatter(
    x=[1, 2, 3, 4],
    y=[1, 2, 3, 4],
    xaxis='x1',
    yaxis='y'
)
trace2 = go.Scatter(
    x=[1, 2, 3, 4],
    y=[0.2, 999, 0.3, 0.4],
    xaxis='x1',
    yaxis='y2'
)

# Layout
layout = dict(
    xaxis = dict(
        title='xaxis',
        range=[0, 4],
    ),
    yaxis = dict(
        title='yaxis',
        range=[-1, 5]
    ),
    yaxis2=dict(
        title='yaxis2',
        titlefont=dict(
            color='#229954'
        ),
        tickfont=dict(
            color='#229954'
        ),
        overlaying='y',
        side='right',
        showgrid=False,
        zeroline=False,
        range=[-1, 1],
        fixedrange=True
    ),
)

data = [ trace1, trace2 ]

figure = dict(
    data=data,
    layout=layout
)

app.layout = html.Div(children=[
    html.H1(children='yaxis2 does not stay fixed'),
    
    html.Button( 'CLICK', id='submit-button' ),
    
    dcc.Graph(
        id='example-graph'
    )
])

@app.callback(
    dash.dependencies.Output('example-graph','figure'),
    [ dash.dependencies.Input('submit-button','n_clicks') ])
def dummy_function( n_clicks ):
    if not(n_clicks==None):
        return figure
    else:
        raise dash.exceptions.PreventUpdate()

if __name__ == '__main__':
    app.run_server(debug=True)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions