I am trying to plot the graph for 25 samples, I am able to plot it individually but I am unable to plot them all in single plot. I need 8 samples plot with line and different colors, 8 samples with dotted lines and different colors and also the remaining with dashed lines with different colors. I would like to plot all of them in one graph.
Thank you.
import matplotlib.pyplot as plt
xs = []
ys = []
for i in range(25):
subregion_average = np.mean(read_data['sub_region'][i], axis =(0,1))
wavelength = read_data['wavelength'][i]
xs.append(wavelength)
ys.append(subregion_average)
for i in range(len(ys)):
colours=['r','g','b','k','r','c','m','y']
if i<=7:
ax.plot(xs[i], ys[i], 'k--', linewidth = 2)
else if 8<=i<=15:
ax.plot(xs[i], ys[i], 'k:', linewidth = 2)
else:
ax.plot(xs[i], ys[i], 'k', linewidth = 2)
ax.set_xlim(min(wavelength), max(wavelength))
ax.tick_params(labelsize = 12)
ax.set_title('Average Spectrum Calibrated sample', fontsize = 14, weight = 'bold')
ax.set_ylabel('Reflectance', fontsize = 14)
ax.set_xlabel('Wavelength in nm', fontsize = 14)
ax.grid(True)
############
SOLUTION: I got the solution for it, it might not be high level but this is how I want the logic and got all graphs in single plot. Thanks for the inputs.
colours = ['r','g','b','k','r','c','m','y','r','g','b','k','r','c','m','y','r','g','b','k','r','c','m','y','g','k']
for i in range(len(ys)):
if i<=7:
plt.plot(xs[i], ys[i], 'k--', c=colours[i], linewidth = 2)
elif 8<=i<=15:
plt.plot(xs[i], ys[i], 'k:', c=colours[i], linewidth = 2)
else:
plt.plot(xs[i], ys[i], 'k', c=colours[i], linewidth = 2)
plt.xlim(min(wavelength), max(wavelength))
plt.tick_params(labelsize = 12)
plt.title('Average Spectrum Calibrated sample', fontsize = 14, weight = 'bold')
plt.ylabel('Reflectance', fontsize = 14)
plt.xlabel('Wavelength in nm', fontsize = 14)
plt.grid(True)
plt.gcf().set_size_inches(12,12)
plt.savefig("Spectrum_Plots",dpi=500)
plt.subplots(nrows, ncols). Then you can loop through the array ofAxesthat you canzipwith the lists of corresponding variables to plot, colors and line styles withzip(axs.flat, xs, ys, colors, linestyles)as shown here. Or you could use an indexing approach usingenumerate(axs.flat)as shown here, or a cycler as suggested by Mr. T.