for a particular purpose, I want to plot 2-3 different figures using matplotlib
and add different graphs to each of these figures. My particular requirement is complex and hard to explain, so I will try to explain with a simpler example.
For example, imagine I have a list of signals called
[signal_1,signal_2,signal_3, .... , signal _40]
where each 'signal_XXX' represents a numpy-array, some of length 5000 and other length 10,000.
I want to plot all these signals in 2 different graphs, depending on their length.
import matplotlib.pyplot as plt
my_signals = [ signal_1,signal_2,....,signal_40]
fig_5000 = plt.figure(1)
fig_10000 = plt.figure(2)
for signal_i in my_signals :
if len(signal_i) == 5000 :
fig_5000.plot(signal_i)
if len(signal_i) == 10000 :
fig_10000.plot(signal_i)
# now I want to individually show these 2 figures
fig_5000.show()
" do something else here "
fig_10000.show()
Obviously the code which I wrote will not work, also on the last part if I use
plt.show()
both graphs will show at the same time, which I don't want.
Is there any way to do the stuff which I want to do using matplotlib ? or should I try something else?
EDIT
I include a 'working' code , with suggestion from Diziet Asahi,
import numpy
import matplotlib.pyplot as plt
my_signals = []
for i in range (0,25):
if i//2 == 0 :
my_signals.append( numpy.random.rand(100))
if i//2 == 1 :
my_signals.append( numpy.random.rand(200))
"""numpy.random.rand craetes an array with random numbers of the given shape.
now we have a list of 50 arrays with 100 and 200 lengths """
fig_100 = plt.figure(1)
ax100 = fig_100.add_subplot(111)
plt.title(" length = 100")
fig_200 = plt.figure(2)
plt.title(" length = 200")
ax200 = fig_200.add_subplot(111)
for arrayzz in my_signals :
if len(arrayzz) == 100 :
ax100.plot(arrayzz)
if len(arrayzz) == 200:
ax200.plot(arrayzz)
plt.show()
This fixes the first part of the earlier problem. Still, I can't show them individually.