Home > Software design >  Setting Multiple Titles for subplots in loop
Setting Multiple Titles for subplots in loop

Time:08-06

I would like to generate a plot title for each of my 4 subplots within a loop. For any reason, only the last element of the name and freq list is used and the for loop does not iterate through the two list in dependance of p. Any ideas how to solve this ?

import matplotlib.pyplot as plt

name = [['1'], ['2'], ['3'],['4']]
freq = ['51', '52', '53','54']
supplier = ['A', 'B']

fig1, axs = plt.subplots(2,2)
for p in range(4):
    [axs[l, k].set_title('Curves for '  name[p][0]   '\n by '   supplier[k]   '@ '   freq[p]) for l in range(2) for k in range(2)]
plt.show()

This is what is generated now: enter image description here

  • Related