# Plotly graphs don't reset after zoom

**URL:** <https://talk.observablehq.com/t/plotly-graphs-dont-reset-after-zoom/2063>\
**Category:** Help\
**Created:** [June 16, 2019, 5:01pm UTC](https://talk.observablehq.com/t/plotly-graphs-dont-reset-after-zoom/2063 "2019-06-16T17:01:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bluprince13](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bluprince13/32/1646_2.png) [@bluprince13](https://talk.observablehq.com/u/bluprince13)\
**Post date:** [June 16, 2019, 5:01pm UTC](https://talk.observablehq.com/t/plotly-graphs-dont-reset-after-zoom/2063/1 "2019-06-16T17:01:43Z")

</div>

I’m getting a really weird error.

See minimal example here: [https://observablehq.com/@bluprince13/plotly-graphs-dont-reset-after-zoom](https://observablehq.com/@bluprince13/plotly-graphs-dont-reset-after-zoom)

For some reason, I get different behaviour depending on whether one cell refers to hardcoded values or to a different cell - even though the values are the same.

Hopefully, you can understand what the problem is from my minimal example. If not, let me know and I can try and explain it better.

---

<div class="post-metadata">

**Author:** ![bgchen](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bgchen/32/784_2.png) [@bgchen](https://talk.observablehq.com/u/bgchen)\
**Post date:** [June 16, 2019, 5:36pm UTC](https://talk.observablehq.com/t/plotly-graphs-dont-reset-after-zoom/2063/2 "2019-06-16T17:36:37Z")

</div>

The issue is with the dependence on `limit`. Its entries get mutated when you zoom in on the plot, and so when you drag the slider and the chart cell is re-evaluated, the chart pulls the new values from `limit` instead of resetting.

To solve this, you can change the chart cell so that it depends on a copy of the array in `limit`; that way when you zoom in, what gets modified is the copy, rather than `limit` itself:

> **[Comparing ‘Plotly graphs don't reset after zoom’ by bluprince13 to ‘Plotly...](https://observablehq.com/compare/ed3152d342a1c500@55...d1be7f93a078139c@59)**
>
> A comparison of two Observable notebooks.

---

<div class="post-metadata">

**Author:** ![bluprince13](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bluprince13/32/1646_2.png) [@bluprince13](https://talk.observablehq.com/u/bluprince13)\
**Post date:** [June 16, 2019, 5:51pm UTC](https://talk.observablehq.com/t/plotly-graphs-dont-reset-after-zoom/2063/3 "2019-06-16T17:51:03Z")

</div>

That makes total sense. Thank you!! How the heck did you figure that out? Have you come across this before?

---

<div class="post-metadata">

**Author:** ![bluprince13](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bluprince13/32/1646_2.png) [@bluprince13](https://talk.observablehq.com/u/bluprince13)\
**Post date:** [June 16, 2019, 6:04pm UTC](https://talk.observablehq.com/t/plotly-graphs-dont-reset-after-zoom/2063/4 "2019-06-16T18:04:17Z")

</div>

Nvm. I think I get how you arrived at that conclusion now.

---

<div class="post-metadata">

**Author:** ![bgchen](https://yyz2.discourse-cdn.com/flex030/user_avatar/talk.observablehq.com/bgchen/32/784_2.png) [@bgchen](https://talk.observablehq.com/u/bgchen)\
**Post date:** [June 17, 2019, 1:10am UTC](https://talk.observablehq.com/t/plotly-graphs-dont-reset-after-zoom/2063/5 "2019-06-17T01:10:20Z")

</div>

> [@bluprince13](#):
>
> How the heck did you figure that out? Have you come across this before?

Yeah, I’ve inflicted many, many frustrating bugs on myself by forgetting that JS objects can get changed “under the hood”. In this case, you gave me a big clue by stating in the notebook that only the x-axis range didn’t reset. When I saw the reference to the cell `limit` in the chart cell, I then tried zooming in on the plot and then clicking on the value of `limit` to see whether it was getting changed. Once I saw that it was getting updated by the zoom operation, that confirmed my suspicions. Then I tried the usual sanitizing technique of “copying an object before passing a reference to it to a function which might modify it” and that did the trick.
