# How to replace a plot in a tab?

**URL:** <https://discourse.bokeh.org/t/how-to-replace-a-plot-in-a-tab/1022>\
**Category:** Community Support\
**Created:** [February 15, 2016, 4:37pm UTC](https://discourse.bokeh.org/t/how-to-replace-a-plot-in-a-tab/1022 "2016-02-15T16:37:22Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@Robert](https://discourse.bokeh.org/u/Robert)\
**Post date:** [February 15, 2016, 4:37pm UTC](https://discourse.bokeh.org/t/how-to-replace-a-plot-in-a-tab/1022/1 "2016-02-15T16:37:22Z")

</div>

Hi!

I’m currently working on changing the axes when converting units in a plot. This is done by a callback on a text-input that does simple math and produces a new array.

As the elements in the new array is approximately 10^-3 times smaller than the original I need to create an additional x-axis and a new line that is linked to the new x-axis.

The question is then how do you grab a figure from a tab, delete it and insert a new plot in the same location in real-time using bokeh serve in the background? Is it done simply with list manipulations? Or can I change the figure directly by assigning it as a variable and setting that variable as a tab and then changing the figure-variable later?

With most sincere thanks,

-Robert

---

<div class="post-metadata">

**Author:** ![Bryan](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/bryan/32/3625_2.png) [@Bryan](https://discourse.bokeh.org/u/Bryan)\
**Post date:** [February 16, 2016, 2:37am UTC](https://discourse.bokeh.org/t/how-to-replace-a-plot-in-a-tab/1022/2 "2016-02-16T02:37:07Z")

</div>

Hi Robert,

I'm a little unclear from your description. Do you need a new plot, or do you just need to update an existing plot with new data? If you are using the default data ranges, then if you replace the data with smaller or larger values, the axes should update automatically. Alternatively, you can explicitly set a new start/end on existing ranges or data ranges. Or are you wanting e.g., two x-axes at the same time? Maybe a drawing or some code would help clarify your use case.

You can certainly replace an entire plot of you want/need to as well (just replace the plot in whatever layout it is in with a new plot). Just trying to understand the situation better

Thanks,

Bryan

> **···**
>
> > On Feb 15, 2016, at 10:37 AM, Robert \<solli.robert@gmail.com\> wrote:
> > 
> > Hi!
> > 
> > I'm currently working on changing the axes when converting units in a plot. This is done by a callback on a text-input that does simple math and produces a new array.
> > 
> > As the elements in the new array is approximately 10^-3 times smaller than the original I need to create an additional x-axis and a new line that is linked to the new x-axis.
> > 
> > The question is then how do you grab a figure from a tab, delete it and insert a new plot in the same location in real-time using bokeh serve in the background? Is it done simply with list manipulations? Or can I change the figure directly by assigning it as a variable and setting that variable as a tab and then changing the figure-variable later?
> > 
> > With most sincere thanks,  
> > -Robert
> > 
> > --  
> > 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 bokeh+unsubscribe@continuum.io.  
> > To post to this group, send email to bokeh@continuum.io.  
> > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/7347d3f5-634a-4c35-8068-688e4272858a%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/7347d3f5-634a-4c35-8068-688e4272858a%40continuum.io%5C).  
> > For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).

---

<div class="post-metadata">

**Author:** ![Robert](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@Robert](https://discourse.bokeh.org/u/Robert)\
**Post date:** [February 16, 2016, 1:36pm UTC](https://discourse.bokeh.org/t/how-to-replace-a-plot-in-a-tab/1022/3 "2016-02-16T13:36:56Z")

</div>

Hi Bryan,

I’m sorry for not being entirely clear. A revision in my code makes the problem somewhat easier. I only wish to re-name the x-axis in a plot in a callback. Each figure exists in a Panel object as a tab in a tabs object.

tab\_plots =

for i in number\_of\_figures:

tab\_plots.append(Panel(child = hplot(figure\_obj, radio\_group, vform(text\_input\_rsf, text\_input\_sputter, text\_input\_crater\_depth)), title = attr\_id))

tabs = Tabs(tabs = tab\_plots)

session = push\_session(curdoc())

session.show()

session.loop\_until\_closed()

And the callback exists on the text\_input\_sputter/crater\_depth objects by an .on\_change trigger. So whichever is easier of changing the current x-axis or simply updating with an additional x-axis.

I hope that clarifies things somewhat.

Sincere thanks,

Robert

tirsdag 16. februar 2016 03.37.12 UTC+1 skrev Bryan Van de ven følgende:

> **···**
>
> > Hi Robert,
> > 
> > I’m a little unclear from your description. Do you need a new plot, or do you just need to update an existing plot with new data? If you are using the default data ranges, then if you replace the data with smaller or larger values, the axes should update automatically. Alternatively, you can explicitly set a new start/end on existing ranges or data ranges. Or are you wanting e.g., two x-axes at the same time? Maybe a drawing or some code would help clarify your use case.
> > 
> > You can certainly replace an entire plot of you want/need to as well (just replace the plot in whatever layout it is in with a new plot). Just trying to understand the situation better
> > 
> > Thanks,
> > 
> > Bryan
> > 
> > > On Feb 15, 2016, at 10:37 AM, Robert [solli....@gmail.com](mailto:solli....@gmail.com) wrote:
> > 
> > > Hi!
> > > 
> > > I’m currently working on changing the axes when converting units in a plot. This is done by a callback on a text-input that does simple math and produces a new array.
> > > 
> > > As the elements in the new array is approximately 10^-3 times smaller than the original I need to create an additional x-axis and a new line that is linked to the new x-axis.
> > > 
> > > The question is then how do you grab a figure from a tab, delete it and insert a new plot in the same location in real-time using bokeh serve in the background? Is it done simply with list manipulations? Or can I change the figure directly by assigning it as a variable and setting that variable as a tab and then changing the figure-variable later?
> > > 
> > > With most sincere thanks,  
> > > -Robert
> > > 
> > > –  
> > > 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 [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).
> > 
> > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).
> > 
> > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/7347d3f5-634a-4c35-8068-688e4272858a%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/7347d3f5-634a-4c35-8068-688e4272858a%40continuum.io).
> > 
> > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).

---

<div class="post-metadata">

**Author:** ![Bryan](https://discourse.bokeh.org/user_avatar/discourse.bokeh.org/bryan/32/3625_2.png) [@Bryan](https://discourse.bokeh.org/u/Bryan)\
**Post date:** [February 19, 2016, 2:13pm UTC](https://discourse.bokeh.org/t/how-to-replace-a-plot-in-a-tab/1022/4 "2016-02-19T14:13:38Z")

</div>

Hi Robert,

I am afraird I am still not quite clear about what exactly you want to happen. When you say "re-name the x-axis in a plot" that makes me think you wnat ot change just the axis label (which you an certainly do with "plot.xaxis.lable = 'new label'" or similar in your callback). But your earlier message seemed indicate that you are changing the data? Did you mean replacing the data entirely and responding to just the new data? Or adding some new data (on smaller scale) in addition to the data already on the plot (and also adding a new, \*second\* axis? I can't tell if you are asking about "twin axis" type situation or not). Perhaps some images or sketches could help clarify.

Bryan

> **···**
>
> > On Feb 16, 2016, at 8:36 AM, Robert \<solli.robert@gmail.com\> wrote:
> > 
> > Hi Bryan,
> > 
> > I'm sorry for not being entirely clear. A revision in my code makes the problem somewhat easier. I only wish to re-name the x-axis in a plot in a callback. Each figure exists in a Panel object as a tab in a tabs object.
> > 
> > &nbsp;&nbsp;&nbsp;&nbsp;tab\_plots =   
> > &nbsp;&nbsp;&nbsp;&nbsp;for i in number\_of\_figures:  
> > &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;tab\_plots.append(Panel(child = hplot(figure\_obj, radio\_group, vform(text\_input\_rsf, text\_input\_sputter, text\_input\_crater\_depth)), title = attr\_id))  
> > &nbsp;&nbsp;&nbsp;&nbsp;  
> > &nbsp;&nbsp;&nbsp;&nbsp;tabs = Tabs(tabs = tab\_plots)  
> > &nbsp;&nbsp;&nbsp;&nbsp;  
> > &nbsp;&nbsp;&nbsp;&nbsp;session = push\_session(curdoc())  
> > &nbsp;&nbsp;&nbsp;&nbsp;session.show()  
> > &nbsp;&nbsp;&nbsp;&nbsp;session.loop\_until\_closed()
> > 
> > And the callback exists on the text\_input\_sputter/crater\_depth objects by an .on\_change trigger. So whichever is easier of changing the current x-axis or simply updating with an additional x-axis.
> > 
> > I hope that clarifies things somewhat.
> > 
> > Sincere thanks,  
> > Robert
> > 
> > tirsdag 16. februar 2016 03.37.12 UTC+1 skrev Bryan Van de ven følgende:  
> > Hi Robert,
> > 
> > I'm a little unclear from your description. Do you need a new plot, or do you just need to update an existing plot with new data? If you are using the default data ranges, then if you replace the data with smaller or larger values, the axes should update automatically. Alternatively, you can explicitly set a new start/end on existing ranges or data ranges. Or are you wanting e.g., two x-axes at the same time? Maybe a drawing or some code would help clarify your use case.
> > 
> > You can certainly replace an entire plot of you want/need to as well (just replace the plot in whatever layout it is in with a new plot). Just trying to understand the situation better
> > 
> > Thanks,
> > 
> > Bryan
> > 
> > \> On Feb 15, 2016, at 10:37 AM, Robert \<solli....@gmail.com\> wrote:  
> > \>  
> > \> Hi!  
> > \>  
> > \> I'm currently working on changing the axes when converting units in a plot. This is done by a callback on a text-input that does simple math and produces a new array.  
> > \>  
> > \> As the elements in the new array is approximately 10^-3 times smaller than the original I need to create an additional x-axis and a new line that is linked to the new x-axis.  
> > \>  
> > \> The question is then how do you grab a figure from a tab, delete it and insert a new plot in the same location in real-time using bokeh serve in the background? Is it done simply with list manipulations? Or can I change the figure directly by assigning it as a variable and setting that variable as a tab and then changing the figure-variable later?  
> > \>  
> > \> With most sincere thanks,  
> > \> -Robert  
> > \>  
> > \> --  
> > \> 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 bokeh+un...@continuum.io.  
> > \> To post to this group, send email to bo...@continuum.io.  
> > \> To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/7347d3f5-634a-4c35-8068-688e4272858a%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/7347d3f5-634a-4c35-8068-688e4272858a%40continuum.io%5C).  
> > \> For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).
> > 
> > --  
> > 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 bokeh+unsubscribe@continuum.io.  
> > To post to this group, send email to bokeh@continuum.io.  
> > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/70ebec6b-f8ad-4ebf-b200-e86c07452682%40continuum.io\](https://groups.google.com/a/continuum.io/d/msgid/bokeh/70ebec6b-f8ad-4ebf-b200-e86c07452682%40continuum.io%5C).  
> > For more options, visit [https://groups.google.com/a/continuum.io/d/optout\](https://groups.google.com/a/continuum.io/d/optout%5C).

---

<div class="post-metadata">

**Author:** ![Robert](https://discourse.bokeh.org/letter_avatar_proxy/v4/letter/r/e95f7d/32.png) [@Robert](https://discourse.bokeh.org/u/Robert)\
**Post date:** [February 19, 2016, 3:11pm UTC](https://discourse.bokeh.org/t/how-to-replace-a-plot-in-a-tab/1022/5 "2016-02-19T15:11:07Z")

</div>

Yeah I just wanted to change the axis label, and it worked out great! I started out thinking i needed to create an additional axis, and as it turns out I did not need to do that. Sorry for the confusion!

Robert

fredag 19. februar 2016 15.13.43 UTC+1 skrev Bryan Van de ven følgende:

> **···**
>
> > Hi Robert,
> > 
> > I am afraird I am still not quite clear about what exactly you want to happen. When you say “re-name the x-axis in a plot” that makes me think you wnat ot change just the axis label (which you an certainly do with “plot.xaxis.lable = ‘new label’” or similar in your callback). But your earlier message seemed indicate that you are changing the data? Did you mean replacing the data entirely and responding to just the new data? Or adding some new data (on smaller scale) in addition to the data already on the plot (and also adding a new, _second_ axis? I can’t tell if you are asking about “twin axis” type situation or not). Perhaps some images or sketches could help clarify.
> > 
> > Bryan
> > 
> > > On Feb 16, 2016, at 8:36 AM, Robert [solli....@gmail.com](mailto:solli....@gmail.com) wrote:
> > 
> > > Hi Bryan,
> > > 
> > > I’m sorry for not being entirely clear. A revision in my code makes the problem somewhat easier. I only wish to re-name the x-axis in a plot in a callback. Each figure exists in a Panel object as a tab in a tabs object.
> > > 
> > > ```
> > > tab_plots = []
> > > 
> > > ```
> > 
> > > ```
> > > for i in number_of_figures:
> > > 
> > > ```
> > 
> > > ```
> > > tab_plots.append(Panel(child = hplot(figure_obj, radio_group, vform(text_input_rsf, text_input_sputter, text_input_crater_depth)), title = attr_id))
> > > 
> > > ```
> > 
> > > ```
> > > tabs = Tabs(tabs = tab_plots)
> > > 
> > > ```
> > 
> > > ```
> > > session = push_session(curdoc())
> > > 
> > > ```
> > 
> > > ```
> > > session.show()
> > > 
> > > ```
> > 
> > > ```
> > > session.loop_until_closed()
> > > 
> > > ```
> > 
> > > And the callback exists on the text\_input\_sputter/crater\_depth objects by an .on\_change trigger. So whichever is easier of changing the current x-axis or simply updating with an additional x-axis.
> > > 
> > > I hope that clarifies things somewhat.
> > 
> > > Sincere thanks,
> > 
> > > Robert
> > > 
> > > tirsdag 16. februar 2016 03.37.12 UTC+1 skrev Bryan Van de ven følgende:
> > 
> > > Hi Robert,
> > > 
> > > I’m a little unclear from your description. Do you need a new plot, or do you just need to update an existing plot with new data? If you are using the default data ranges, then if you replace the data with smaller or larger values, the axes should update automatically. Alternatively, you can explicitly set a new start/end on existing ranges or data ranges. Or are you wanting e.g., two x-axes at the same time? Maybe a drawing or some code would help clarify your use case.
> > > 
> > > You can certainly replace an entire plot of you want/need to as well (just replace the plot in whatever layout it is in with a new plot). Just trying to understand the situation better
> > > 
> > > Thanks,
> > > 
> > > Bryan
> > > 
> > > > On Feb 15, 2016, at 10:37 AM, Robert [solli....@gmail.com](mailto:solli....@gmail.com) wrote:
> > > > 
> > > > Hi!
> > > > 
> > > > I’m currently working on changing the axes when converting units in a plot. This is done by a callback on a text-input that does simple math and produces a new array.
> > > > 
> > > > As the elements in the new array is approximately 10^-3 times smaller than the original I need to create an additional x-axis and a new line that is linked to the new x-axis.
> > > > 
> > > > The question is then how do you grab a figure from a tab, delete it and insert a new plot in the same location in real-time using bokeh serve in the background? Is it done simply with list manipulations? Or can I change the figure directly by assigning it as a variable and setting that variable as a tab and then changing the figure-variable later?
> > > > 
> > > > With most sincere thanks,  
> > > > -Robert
> > > > 
> > > > –  
> > > > 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 [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).  
> > > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).  
> > > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/7347d3f5-634a-4c35-8068-688e4272858a%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/7347d3f5-634a-4c35-8068-688e4272858a%40continuum.io).  
> > > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).
> > > 
> > > –  
> > > 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 [bokeh+un...@continuum.io](mailto:bokeh+un...@continuum.io).
> > 
> > > To post to this group, send email to [bo...@continuum.io](mailto:bo...@continuum.io).
> > 
> > > To view this discussion on the web visit [https://groups.google.com/a/continuum.io/d/msgid/bokeh/70ebec6b-f8ad-4ebf-b200-e86c07452682%40continuum.io](https://groups.google.com/a/continuum.io/d/msgid/bokeh/70ebec6b-f8ad-4ebf-b200-e86c07452682%40continuum.io).
> > 
> > > For more options, visit [https://groups.google.com/a/continuum.io/d/optout](https://groups.google.com/a/continuum.io/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://discourse-uploads.bokeh.org/original/2X/1/14eb24f9e10e4e9b78e3f10f66c04ffa96446e5a.svg) [@system](https://discourse.bokeh.org/u/system)\
**Post date:** [July 21, 2021, 9:07pm UTC](https://discourse.bokeh.org/t/how-to-replace-a-plot-in-a-tab/1022/6 "2021-07-21T21:07:37Z")

</div>


