I don't fully understand your workspace and variables from your provided scripts, but in principle it's simple to loop through any iterable in python and use matplotlib
commands to call plots within the loop. Here is an example:
color_list
is a list of hex strings, indicating colorper plot
mydict
is your parent dictionary (or any subdictionary, access accordingly)
- I assume your data is in
mydict[key]
# plotting recursively in one plot
fig, ax = plt.subplots(1,1,figsize=(12,8))
for key, color in zip(mydict.keys(), color_list):
ax.plot(mydict[key], label=key, ls='--', color=color)
# plotting recursively in multiple subplots (single column)
fig, ax = plt.subplots(5,1,figsize=(14,12))
for i,key,color in enumerate(zip(mydict.keys(), color_list)):
ax[i,1].plot(mydict[key], label=key, ls='--', color=color)
Treat individual subplot settings within your loop. You can then finalize parent plot properties (such as the legend or axes limits) outside the loop. Of course, things get more tricky if you need to divide subplots across multiple axes (i.e. in a grid) and you may then want to create a function using the modulo %
to get from a single index i
to a grid nrow, ncol
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…