# Callback for axis range

**URL:** <https://community.plotly.com/t/callback-for-axis-range/67742>\
**Category:** Dash Python\
**Created:** [September 7, 2022, 9:21pm UTC](https://community.plotly.com/t/callback-for-axis-range/67742 "2022-09-07T21:21:55Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Miguelxda](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@Miguelxda](https://community.plotly.com/u/Miguelxda)\
**Post date:** [September 7, 2022, 9:21pm UTC](https://community.plotly.com/t/callback-for-axis-range/67742/1 "2022-09-07T21:21:55Z")

</div>

Hi! I would like to know if there is any callback that could give me the axis range (for example yaxis) when selecting that range in a graph with the cursor.  
Thank you!

---

<div class="post-metadata">

**Author:** ![trailboss](https://avatars.discourse-cdn.com/v4/letter/t/f14d63/32.png) [@trailboss](https://community.plotly.com/u/trailboss)\
**Post date:** [September 8, 2022, 5:33am UTC](https://community.plotly.com/t/callback-for-axis-range/67742/2 "2022-09-08T05:33:38Z")

</div>

You need to access “relayoutData” from the figure in the callback. That will give you a dict with xaxis and yaxis ranges upon zooming in or out.

```auto
layout = html.Div(
    [
        dcc.Graph(id="graph", figure=px.scatter(x=[1, 2, 3], y=[1, 2, 3])),
        html.Div(id="layout_output"),
    ]
)
@callback(
    Output("layout_output", "children"), Input("graph", "relayoutData"),
)
def get_layout(relayout_data: dict):
    if relayout_data:
        return json.dumps(relayout_data)
    raise dash.exceptions.PreventUpdate

```

---

<div class="post-metadata">

**Author:** ![Miguelxda](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@Miguelxda](https://community.plotly.com/u/Miguelxda)\
**Post date:** [September 8, 2022, 7:50am UTC](https://community.plotly.com/t/callback-for-axis-range/67742/3 "2022-09-08T07:50:19Z")

</div>

Thank you very much! Could you please give me the source of that information?

---

<div class="post-metadata">

**Author:** ![AIMPED](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/aimped/32/21758_2.png) [@AIMPED](https://community.plotly.com/u/AIMPED)\
**Post date:** [September 8, 2022, 8:14am UTC](https://community.plotly.com/t/callback-for-axis-range/67742/4 "2022-09-08T08:14:46Z")

</div>

This might be helpful:

> **[Part 4. Interactive Graphing and Crossfiltering | Dash for Python...](https://dash.plotly.com/interactive-graphing)**
>
> Graphs can be inputs as well as outputs: bind interactivity to the Dash \`Graph\` component whenever you hover, click, or select points on your chart.

---

<div class="post-metadata">

**Author:** ![Miguelxda](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@Miguelxda](https://community.plotly.com/u/Miguelxda)\
**Post date:** [September 8, 2022, 9:52am UTC](https://community.plotly.com/t/callback-for-axis-range/67742/5 "2022-09-08T09:52:24Z")

</div>

> [@trailboss](#):
>
> ```auto
> @callback(
> Output("layout_output", "children"), Input("graph", "relayoutData"),
> )
> def get_layout(relayout_data: dict):
> if relayout_data:
> return json.dumps(relayout_data)
> raise dash.exceptions.PreventUpdate
> 
> ```

Thank you very much! I have another question: How could i see all Input and output callbacks for any dcc or html components included in dash?

---

<div class="post-metadata">

**Author:** ![Miguelxda](https://avatars.discourse-cdn.com/v4/letter/m/7cd45c/32.png) [@Miguelxda](https://community.plotly.com/u/Miguelxda)\
**Post date:** [September 8, 2022, 10:56am UTC](https://community.plotly.com/t/callback-for-axis-range/67742/6 "2022-09-08T10:56:58Z")

</div>

I have a problem with that code:  
I wrote a slightly variation, that works fine, except for a small problem, that is that I cant use reset axes or autoscale in my graph

> @app.callback(  
> Output(‘date\_picker\_consumption’, “start\_date”),  
> Output(‘date\_picker\_consumption’, “end\_date”),  
> Input(“consumption\_graph\_plotly”, “relayoutData”),  
> )  
> def get\_layout(relayout\_data: dict):
> 
> ```
> if relayout_data:
> if 'xaxis.range[0]' in relayout_data and 'xaxis.range[1]' in relayout_data:
> 
> return relayout_data['xaxis.range[0]'].split()[0], relayout_data['xaxis.range[1]'].split()[0]
> raise dash.exceptions.PreventUpdate
> 
> ```

---

<div class="post-metadata">

**Author:** ![trailboss](https://avatars.discourse-cdn.com/v4/letter/t/f14d63/32.png) [@trailboss](https://community.plotly.com/u/trailboss)\
**Post date:** [September 8, 2022, 5:30pm UTC](https://community.plotly.com/t/callback-for-axis-range/67742/8 "2022-09-08T17:30:45Z")

</div>

Pretty much any property of html or dcc components can be used in a callback. You can inspect the object or read the docs to see what is available.

> **[Graph | Dash for Python Documentation | Plotly](https://dash.plotly.com/dash-core-components/graph)**
>
> Graph
