Is there a way to clear a figure?

I’m iteratively making figures in a for-loop.

I tried to make a list of figures and iterate over them, expecting them to be unique objects and therefore distinct figures, but when I generate and save the figures, they incrementally have axes duplicated for every subsequent figure in the list.

list = []
for i in range(0, num_jumps): list.append(pygmt.Figure())

for jumpNum in range(0, num_jumps):
    fig = list[i]
    # do stuff to fig

Any idea or ways to clear it? Ideally I’d just use one fig object and clear it every iteration, but if there’s a way to do it via the way I’m trying to do above that’s fine too.

Remove all frames (see -B’s parameter documentation) then finish the script with basemap module. That should do the trick I think

Hello @geofan,

maybe you are using the wrong index in your second loop? And it should be jumpNum, not i ?

for jumpNum in range(0, num_jumps):
    fig = list[jumpNum]  # not i
    # do stuff to fig

Yvonne - great catch, what a silly mistake! That fixed it for me.

@PlanetGus, noted as well, thanks for the insight.