GenericMappingTools / GenericMappingTools/pygmt
Copy `pygmt.Figure()` instance or object to a new variable and keep the initial variable as is
- Dominant language
- Python
- Stars
- 874
- Forks
- 255
- Avg merge
- 1d 21h
- Merged PRs (30d)
- 40
Description
Copying a `pygmt.Figure()` instance or object to a new variable can be useful, e.g., within a Jupyter notebook for re-running cells with different arguments passed to the parameters to test different visualizations. However, this seems to be not straight forward. In the example below, I would like to achieve that `fig1` remains as is after adding features to `fig2`. Neither running `fig2 = fig1` nor running `fig2 = copy.deepcopy(fig1)` before changing `fig2` works as expected. Maybe there is a relationship to continuing the GMT session and not creating a new one?
Related to: https://github.com/GenericMappingTools/agu24workshop/pull/8#issuecomment-2495692791, https://github.com/GenericMappingTools/agu24workshop/pull/8#issuecomment-2495929549
```python
import pygmt
size = 5
fig1 = pygmt.Figure()
fig1.basemap(projection="X5c", region=[-5, 5, -5, 5], frame=True)
fig1.show()
fig2 = fig1
# OR (both does not work as expected)
# fig2 = copy.deepcopy(fig1)
fig2.plot(x=0, y=0, style="c1c")
fig2.show()
fig1.show() # Now fig1 also contains the circle and is identical to fig2
```
| fig1 | fig2 | fig1|
| --- | --- | --- |
|  |  |  |
Contributor guide
Assessment
This issue has not been assessed yet.