Creating copy.deepcopy(my_figure) produces unexpected results.

To save on processing time, I am trying to “cache” Figure objects by calling my_figure = figure(…), adding my glyphs with my_figure.add_glyph(…), and then storing my_figure in a cache:
my_cache = {‘saved_plot_1’: my_figure}

``

When I need to pull it out of the cache for plotting, I do so by making a deep copy of it:
self.my_gridplot.children = [copy.deepcopy(my_cache[‘saved_plot_1’])]

``

This works well on the first plotting, but subsequent plots produce plots of different sizes from the original. I suspect this is because the act of calling figure(…) or add_glyph(…) is causing some wanted side effect that no longer happens on subsequent pulls from the cache.

How do I reuse a deep copy of an object returned by figure(…) to create a plot guaranteed to be formatted (same size, spacing, all of the same attributes) the same each time?

Thank you,

Jeff

I don't think this is a practice that has ever been explored in any depth. This kind of copying is certainly not a constraint the classes were designed under (they are designed to be declarative, and to know how to serialize and validate themselves, first and foremost). Do you you have any profiling results that characterize to what extent (if any) figure creation is actually bottleneck or your application, and also any comparison to how much better (if at all) a copy.deepcopy performs? I am skeptical that there is any appreciable difference but of course I would be swayed by real data.

Bryan

···

On Jan 8, 2016, at 3:13 PM, [email protected] wrote:

To save on processing time, I am trying to "cache" Figure objects by calling my_figure = figure(...), adding my glyphs with my_figure.add_glyph(...), and then storing my_figure in a cache:
my_cache = {'saved_plot_1': my_figure}

When I need to pull it out of the cache for plotting, I do so by making a deep copy of it:
self.my_gridplot.children = [copy.deepcopy(my_cache['saved_plot_1'])]

This works well on the first plotting, but subsequent plots produce plots of different sizes from the original. I suspect this is because the act of calling figure(...) or add_glyph(...) is causing some wanted side effect that no longer happens on subsequent pulls from the cache.

How do I reuse a deep copy of an object returned by figure(...) to create a plot guaranteed to be formatted (same size, spacing, all of the same attributes) the same each time?

Thank you,
Jeff

--
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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/62aea1b3-7bb5-4cd9-92f3-a6f963e231ee%40continuum.io\.
For more options, visit https://groups.google.com/a/continuum.io/d/optout\.

Thank you for your quick reply! For us it’s not the actual act of calling figure() and adding glyphs that is the bottleneck, but rather all of the code that goes into deciding how to build the figure and what to add to it. These are non-standard graphs that have a lot of complexity. And this app has many, many different graphs so that processing time is high every time a figure is being built. We’d love to be able to “save a graph” and use it later without having to rebuild it. Using the method I described, the results are so close to what I want but with some unfortunate differences, like the size of the figure has changed or it is now partially overlapped by a neighboring plot (but one that is even in a different VBox()).

If you have any advice, I’d really appreciate it.

Thank you!

Jeff

···

On Friday, January 8, 2016 at 4:24:45 PM UTC-5, Bryan Van de ven wrote:

I don’t think this is a practice that has ever been explored in any depth. This kind of copying is certainly not a constraint the classes were designed under (they are designed to be declarative, and to know how to serialize and validate themselves, first and foremost). Do you you have any profiling results that characterize to what extent (if any) figure creation is actually bottleneck or your application, and also any comparison to how much better (if at all) a copy.deepcopy performs? I am skeptical that there is any appreciable difference but of course I would be swayed by real data.

Bryan

On Jan 8, 2016, at 3:13 PM, [email protected] wrote:

To save on processing time, I am trying to “cache” Figure objects by calling my_figure = figure(…), adding my glyphs with my_figure.add_glyph(…), and then storing my_figure in a cache:

my_cache = {‘saved_plot_1’: my_figure}

When I need to pull it out of the cache for plotting, I do so by making a deep copy of it:

self.my_gridplot.children = [copy.deepcopy(my_cache[‘saved_plot_1’])]

This works well on the first plotting, but subsequent plots produce plots of different sizes from the original. I suspect this is because the act of calling figure(…) or add_glyph(…) is causing some wanted side effect that no longer happens on subsequent pulls from the cache.

How do I reuse a deep copy of an object returned by figure(…) to create a plot guaranteed to be formatted (same size, spacing, all of the same attributes) the same each time?

Thank you,

Jeff


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 [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/62aea1b3-7bb5-4cd9-92f3-a6f963e231ee%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.

In 0.11, one possibility could be to keep the figure as json and parse the json each time. Don’t know how that would benchmark though. Possibly it would work better if you kept any large data arrays out of the json.

Havoc

···

On Jan 8, 2016, at 4:13 PM, [email protected] wrote:

To save on processing time, I am trying to “cache” Figure objects by calling my_figure = figure(…), adding my glyphs with my_figure.add_glyph(…), and then storing my_figure in a cache:
my_cache = {‘saved_plot_1’: my_figure}

``

When I need to pull it out of the cache for plotting, I do so by making a deep copy of it:
self.my_gridplot.children = [copy.deepcopy(my_cache[‘saved_plot_1’])]

``

This works well on the first plotting, but subsequent plots produce plots of different sizes from the original. I suspect this is because the act of calling figure(…) or add_glyph(…) is causing some wanted side effect that no longer happens on subsequent pulls from the cache.

How do I reuse a deep copy of an object returned by figure(…) to create a plot guaranteed to be formatted (same size, spacing, all of the same attributes) the same each time?

Thank you,

Jeff

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 [email protected].

To post to this group, send email to [email protected].

To view this discussion on the web visit https://groups.google.com/a/continuum.io/d/msgid/bokeh/62aea1b3-7bb5-4cd9-92f3-a6f963e231ee%40continuum.io.

For more options, visit https://groups.google.com/a/continuum.io/d/optout.