OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

matplotlib blitting (animated plot) can't resize figure

  • Thread starter Thread starter LukasFun
  • Start date Start date
L

LukasFun

Guest
I have an animated line using the example given on the matplotlib site:

Code:
import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2 * np.pi, 100)

fig, ax = plt.subplots()

(ln,) = ax.plot(x, np.sin(x), animated=True)

plt.show(block=False)
plt.pause(0.1)

bg = fig.canvas.copy_from_bbox(fig.bbox)

ax.draw_artist(ln)

fig.canvas.blit(fig.bbox)

for j in range(100):
    fig.canvas.restore_region(bg)
    ln.set_ydata(np.sin(x + (j / 100) * np.pi))
    ax.draw_artist(ln)
    fig.canvas.blit(fig.bbox)
    fig.canvas.flush_events()

This yields the plot:

regular figure

When I resize the window of the figure, it no longer works as intended:

resized figure

What is the problem here?
<p>I have an animated line using the example given on the <a href="https://matplotlib.org/stable/tutorials/advanced/blitting.html#minimal-example" rel="nofollow noreferrer">matplotlib site</a>:</p>
<pre class="lang-py prettyprint-override"><code>import matplotlib.pyplot as plt
import numpy as np

x = np.linspace(0, 2 * np.pi, 100)

fig, ax = plt.subplots()

(ln,) = ax.plot(x, np.sin(x), animated=True)

plt.show(block=False)
plt.pause(0.1)

bg = fig.canvas.copy_from_bbox(fig.bbox)

ax.draw_artist(ln)

fig.canvas.blit(fig.bbox)

for j in range(100):
fig.canvas.restore_region(bg)
ln.set_ydata(np.sin(x + (j / 100) * np.pi))
ax.draw_artist(ln)
fig.canvas.blit(fig.bbox)
fig.canvas.flush_events()
</code></pre>
<p>This yields the plot:</p>
<p><a href="https://i.sstatic.net/qPF9f.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/qPF9f.png" alt="regular figure" /></a></p>
<p>When I resize the window of the figure, it no longer works as intended:</p>
<p><a href="https://i.sstatic.net/A1ZCh.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/A1ZCh.jpg" alt="resized figure" /></a></p>
<p>What is the problem here?</p>
 

Latest posts

Top