5
votes

I'm plotting a line and updating it in a loop. When I pan the plot at some point during the execution and then click "Reset original view" in the interactive matplotlib window, I am taken back to the plot state from the moment when I started zooming/panning it. Is there a way to see the full extents of the plot instead? Even better, is there a way to tell matplotlib to keep updating the view after this operation?

python 3.4.3, matplotlib 1.4.3

import matplotlib
matplotlib.use('Qt4Agg')
import matplotlib.pyplot as plt
import numpy as np

fig, ax1 = plt.subplots()
ax2 = ax1.twinx()
values_v = []
values_i = []
ln1, = ax1.plot(values_i, values_v, color='green')
plt.ion()
plt.show()

for i in range(40):
    scopevals = [i, i+2+np.random.rand()]

    values_v.append(scopevals[0])
    values_i.append(scopevals[1])

    ln1.set_data([values_i, values_v])

    ax1.relim()
    ax1.autoscale_view(True,True,True)

    plt.pause(1)
1
I have been looking for an answer to this for a while now. Did you ever find something? - Nikolaus Demmel
@NikolausDemmel unfortunately, I haven't found a solution - alkamid
Thanks for the response. The only thing that I found was clearing the axes and re-adding all plots and patches, which serves as a worksaround, but needs additional manual bookkeeping. - Nikolaus Demmel

1 Answers

0
votes

I encountered the problem when I displayed different images in the same figure.

Clearing the old figure helped me:

plt.figure(1) #the figure you re working with
plt.clf() #clear figure
plt.imshow(self.sample_image)  # show new picture

And the Original view should work again. Cheers Andy