0

I've been looking online for help but nothing that I have seen is helping me to add space between the xticks without losing any xtick labels on the x axis. Here is my code and the things that I have tried to get the figure below to the current layout. Is there an auto-adjust that works? "plt.tight_layout" should do that but doesn't seem to work for me. thank you for help here. And, the plt.suptitle is not centered above the month (February).

#CALC VARIABILITY AND PLOT BOXPLOTS for ea month
sitenames = df3.plant_name.unique().tolist()
months = ['JANUARY','FEBRUARY','MARCH','APRIL','MAY','JUNE','JULY','AUGUST','SEPTEMBER','OCTOBER','NOVEMBER','DECEMBER']
from datetime import datetime
monthn = datetime.now().month
newList = list()
for i in range(monthn-1):
    newList.append(months[(i)%12])
print(newList)
for i, month in  enumerate(newList,1):
    #plt.figure()
    #fig, ax = plt.subplots()
    #ax = df3[df3['month']==i].boxplot(by='plant_name',column='Var',grid=False)
    datey = datetime.today().strftime("%Y")
    ax = df3[df3['month']==i].plot(kind='scatter',x='plant_name',y='Var',marker='.',s=5,grid=False)
    stdp[stdp['month']==i].plot(kind='scatter', x = 'plant_name', 
y='Var',color='k',marker='_',s=200,label = '1+Std', grid=False,ax=ax)
    stdn[stdn['month']==i].plot(kind='scatter', x = 'plant_name', 
y='Var',color='k',marker='_',s=200,label = '1-Std', grid=False,ax=ax)
    stdp2[stdp2['month']==i].plot(kind='scatter', x = 'plant_name', 
y='Var',color='k',marker='_',s=50,label = '2+Std',grid=False,ax=ax)
    stdn2[stdn2['month']==i].plot(kind='scatter', x = 'plant_name', 
y='Var',color='k',marker='_',s=50,label = '2-Std',grid=False,ax=ax)
    medn[medn['month']==i].plot(kind='scatter', x = 'plant_name', 
y='Var',color='g',marker='_',s=90,label = 'p50',grid=False,ax=ax)
    df3c[df3c['month']==i].plot(kind='scatter', x = 'plant_name', y='Var',color='r',label = 
datey,grid=False,ax=ax)
    # Save the default tick positions, so we can reset them...
    locs, labels = plt.xticks()
    plt.xticks(rotation=90, ha='center')
    plt.suptitle('1991-2020 ERA5 WIND PRODUCTION',y=1)
    plt.title(months[i-1])
    plt.xlabel('SITE')
    plt.ylabel('VARIABILITY')
    #plt.legend()
    ax.legend(loc='center left', bbox_to_anchor=(1, 0.5),prop={'size': 8})
    plt.tick_params(axis='x', which='major', labelsize=10)
    plt.tight_layout(rect=[0, 0, 2, 1])
    plt.subplots_adjust(bottom=0.1)

Without "plot_tight_layout(rect[0, 0, 2, 1])"

enter image description here

And, with "plot_tight_layout(rect[0, 0, 2, 1])" included:

enter image description here

user2100039
  • 1,280
  • 2
  • 16
  • 31
  • your title says you want to add space between the x axis ticks and the labels; your question says you want to add space between the x axis ticks and the data plotted above them. Which is it? – tmdavison Mar 24 '21 at 13:58
  • thanks for the clarity check - the title is accurate and i've edited the narrative. – user2100039 Mar 24 '21 at 14:55
  • Just make your figure wider. https://stackoverflow.com/questions/38294852/making-a-chart-bigger-in-size – Jody Klymak Mar 24 '21 at 17:16

0 Answers0