I want to display multiple figure in Matplotlib. Here's my code:
for i in range(8):
a = sitk.ReadImage("000%d.IMA"%(i+1))
...
plt.figure(i+1)
plt.imshow(a_np,cmap=plt.cm.gray)
However, figure(1) to figure(7) will show during the process but only figure(8) stay in the end. How can I see all of the figures at the same time? It confused me that my environment is Ipython notebook when I change the environment to spyder the result will be correct.
If you want 8 different figures in 8 different windows, here is an example that will work:
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(0,10)
y = np.sin(x)
for i in range(8):
plt.plot(x,y)
plt.figure(i+1)
plt.show()
This will plot 8 different windows with x vs y
and all the windows will stay "alive" until you close them.
Make sure you call plt.show()
outside the for
loop
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With