Open
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: GenericMappingTools/agu24workshop#8 (comment), GenericMappingTools/agu24workshop#8 (comment)
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 |
---|---|---|
![]() |
![]() |
![]() |