Feb-09-2019, 01:09 PM
I'm very new to Python so apologies first for being so simple and secondly if I ask for help in the wrong way. I will get there. I have a script working that goes through a loop plotting 13 test data on one subplot for 40 locations, making 40 graphs with 13 lines. The code runs fine but when I try to put these all on figure (so I have 40 graphs arranged in a 45 panel formation) it goes wrong. I get my 40 axes in a 45 formation but they have no data in them and the axes scale incorrectly to what I have asked it to do. My original working code for the individual figures was:
fig, ax = plt.subplots()
to
fig, ax = plt.subplots(4,5)
But clearly not. I've tried the usual places and the matplotlib site suggests this is the correct way to do it but as I said I am brand new to this so I am probably missing something obvious and it's very hard to know where you are going wrong when its a new skill. I may not even understand the answer if someone gives it to me but I have to learn. There are no errors shown in the command panel. Thanks.
for j in range(40): #loop through locations fig, ax = plt.subplots() #set up for plot LocName = alldata_pd.iloc[1,1+j*41] for i in range(13): ##loop through each time for a single location Depths = alldata_pd.iloc[16:34,3+j*41+i*3] Temps = alldata_pd.iloc[16:34,5+j*41+i*3] TimeName = alldata_pd.iloc[15,5++j*41+i*3] ax.plot(Temps,Depths,color=plotcolours[i],label=TimeName) #set up plot axes etc ax.legend(loc='lower left') ax.set_ylabel('Depth (mbgl)',fontsize=10) ax.set_xlabel('Temperature $^\circ$C',fontsize=10) ax.set_title(LocName) ax.set_xlim(5,20) ax.set_ylim(22,0) #save figure fig_dir = data_dir plt.savefig(fig_dir+'\\'+LocName+'.png',dpi=300)I thought I could get the desired result by simply changing this line:
fig, ax = plt.subplots()
to
fig, ax = plt.subplots(4,5)
But clearly not. I've tried the usual places and the matplotlib site suggests this is the correct way to do it but as I said I am brand new to this so I am probably missing something obvious and it's very hard to know where you are going wrong when its a new skill. I may not even understand the answer if someone gives it to me but I have to learn. There are no errors shown in the command panel. Thanks.