Skip to content

Can't copy.deepcopy a Plotly figure #1165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
rmarren1 opened this issue Sep 7, 2018 · 6 comments
Closed

Can't copy.deepcopy a Plotly figure #1165

rmarren1 opened this issue Sep 7, 2018 · 6 comments
Assignees
Milestone

Comments

@rmarren1
Copy link

rmarren1 commented Sep 7, 2018

This does not work:

>>> from copy import deepcopy
>>> import plotly.graph_objs as go
>>> figure = go.Figure(data=[go.Scatter(x=[1,2,3], y=[1,2,3])], layout=go.Layout())
>>> deepcopy(figure)

and gives the following error:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ryan/.virtualenvs/dash-3.7/lib/python3.7/copy.py", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/home/ryan/.virtualenvs/dash-3.7/lib/python3.7/copy.py", line 280, in _reconstruct
    state = deepcopy(state, memo)
  File "/home/ryan/.virtualenvs/dash-3.7/lib/python3.7/copy.py", line 150, in deepcopy
    y = copier(x, memo)
  File "/home/ryan/.virtualenvs/dash-3.7/lib/python3.7/copy.py", line 240, in _deepcopy_dict
    y[deepcopy(key, memo)] = deepcopy(value, memo)
  File "/home/ryan/.virtualenvs/dash-3.7/lib/python3.7/copy.py", line 180, in deepcopy
    y = _reconstruct(x, memo, *rv)
  File "/home/ryan/.virtualenvs/dash-3.7/lib/python3.7/copy.py", line 281, in _reconstruct
    if hasattr(y, '__setstate__'):
  File "/home/ryan/.virtualenvs/dash-3.7/lib/python3.7/site-packages/plotly/basedatatypes.py", line 3537, in __getattr__
    if prop in self._subplotid_props:
  File "/home/ryan/.virtualenvs/dash-3.7/lib/python3.7/site-packages/plotly/basedatatypes.py", line 3537, in __getattr__
    if prop in self._subplotid_props:
  File "/home/ryan/.virtualenvs/dash-3.7/lib/python3.7/site-packages/plotly/basedatatypes.py", line 3537, in __getattr__
    if prop in self._subplotid_props:
  [Previous line repeated 490 more times]
  File "/home/ryan/.virtualenvs/dash-3.7/lib/python3.7/site-packages/plotly/basedatatypes.py", line 3536, in __getattr__
    prop = self._strip_subplot_suffix_of_1(prop)
  File "/home/ryan/.virtualenvs/dash-3.7/lib/python3.7/site-packages/plotly/basedatatypes.py", line 3504, in _strip_subplot_suffix_of_1
    prop_tuple = BaseFigure._str_to_dict_path(prop)
  File "/home/ryan/.virtualenvs/dash-3.7/lib/python3.7/site-packages/plotly/basedatatypes.py", line 745, in _str_to_dict_path
    if isinstance(key_path_str, string_types) and \
RecursionError: maximum recursion depth exceeded while calling a Python object

I am using plotly==3.1.0 and Python==3.7.0

@jonmmease
Copy link
Contributor

Thanks for the report.

Copying / pickling figures directly isn't possible yet, but it will happen eventually. In the meantime, you can accomplish a deep copy with new_fig = Figure(fig).

@rmarren1
Copy link
Author

rmarren1 commented Sep 8, 2018

Okay, thanks for the info! I found a work-around for my use-case, but will leave this open for future people who get caught up on this.

@jonmmease
Copy link
Contributor

Done in #1191

@shllgtca
Copy link

shllgtca commented Jun 23, 2020

@jonmmease I see that you did the modifications but I still don't get to deep copy Matplotlib figures with: copy.deepcopy

Are those modifications available already ?

@jonmmease
Copy link
Contributor

Hi @shllgtca, these changes (and this repository) are for the plotly.py library not matplotlib. I'd recommend searching/asking about matplotlib over at https://discourse.matplotlib.org/.

@shllgtca
Copy link

shllgtca commented Jul 28, 2020

ops, sorry @jonmmease for the confusion, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants