Open
Description
Instead of
fig.layout.showlegend = False
fig.write_image('plot.pdf')
fig.layout.showlegend = True
it would be nice to write
from plotly.express import plotly_patch # or similar
with plotly_patch(fig.layout, showlegend=False):
fig.write_image('plot.pdf')
I tried
from unittest.mock import patch
with patch.dict(fig.layout, showlegend=False):
fig.write_image('plot.pdf')
which unfortunately doesn't correctly restore the previous value but tries to delete the patched keys which is undesired behavior and raises AttributeError
to boot:
1906 """Unpatch the dict."""
1907 if self._original is not None:
-> 1908 self._unpatch_dict()
...
1934 keys = list(in_dict)
1935 for key in keys:
-> 1936 del in_dict[key]
AttributeError: __delitem__
Related
Found this forum post where such a context manager was welcomed.