Amanda C
Amanda C

Reputation: 21

Change the fontsize of x/yticks in all subplots with same labels

I'm trying to make the font size of the x/yticks of each subplot larger. I've tried using

ax.set_xticklabels(xlabels, Fontsize= )

but I don't want to specify new labels. I want the same ones that were defaulted on the plot (see image below). There are 3 total subplots and I'd like to increase the tick size of all of them.

Part of Code

markers = ['s','^','d','*','o']
colors = ['crimson', 'blueviolet', 'limegreen', 'mediumblue', 'hotpink']

fig,ax = plt.subplots(2, 2, dpi=300, figsize=(30, 25))
fig.delaxes(ax[1,1])
fig.tight_layout()
plt.rcParams['axes.grid'] = True
#plt.xticks(fontsize=24)

x=data['CPR']
y=data['DLP']
for xp, yp, m, c, t in zip(x,y,markers, colors, targets):
    ax[0,0].scatter(xp,yp,s=150,marker=m, color=c, label=t, zorder=1)
ax[0,0].errorbar(data['CPR'],data['DLP'],xerr=data['CPR_stddev'],yerr=data['DLP_stddev'],
               ls='none',
               ecolor='slategray',
               elinewidth=1,
               barsabove=False)  
ax[0,0].grid(color='gray', linestyle='--', linewidth=0.5)
ax[0,0].set_title('CPR vs DLP',fontsize='40')
handles, labels = ax[0,0].get_legend_handles_labels()
fig.legend(handles, labels, scatterpoints=1, borderpad=0.2, loc='upper left', fontsize=24)
ax[0,0].set_xlabel('CPR',fontsize=30)
ax[0,0].set_ylabel('DLP',fontsize=30)
ax[0,0].set_xlim([0,1.2])
####ax[0,0].set_xticks(fontsize=24)
plt.xticks(fontsize=24)
#plt.show()

Current output

***This is for a research poster -- any other recommendations welcome.

Upvotes: 0

Views: 2810

Answers (1)

Davide_sd
Davide_sd

Reputation: 13150

Try this:

markers = ['s','^','d','*','o']
colors = ['crimson', 'blueviolet', 'limegreen', 'mediumblue', 'hotpink']

fig,ax = plt.subplots(2, 2, dpi=300, figsize=(30, 25))
fig.delaxes(ax[1,1])
fig.tight_layout()
plt.rcParams['axes.grid'] = True
#plt.xticks(fontsize=24)

x=data['CPR']
y=data['DLP']
for xp, yp, m, c, t in zip(x,y,markers, colors, targets):
    ax[0,0].scatter(xp,yp,s=150,marker=m, color=c, label=t, zorder=1)
ax[0,0].errorbar(data['CPR'],data['DLP'],xerr=data['CPR_stddev'],yerr=data['DLP_stddev'],
               ls='none',
               ecolor='slategray',
               elinewidth=1,
               barsabove=False)  
ax[0,0].grid(color='gray', linestyle='--', linewidth=0.5)
ax[0,0].set_title('CPR vs DLP',fontsize='40')
handles, labels = ax[0,0].get_legend_handles_labels()
fig.legend(handles, labels, scatterpoints=1, borderpad=0.2, loc='upper left', fontsize=24)
ax[0,0].set_xlabel('CPR',fontsize=30)
ax[0,0].set_ylabel('DLP',fontsize=30)
ax[0,0].set_xlim([0,1.2])

# loop over all axes
for a in ax.flatten():
    a.tick_params(axis='both', which='major', labelsize=24)
    a.tick_params(axis='both', which='minor', labelsize=20)
plt.tight_layout()
plt.show()

Upvotes: 1

Related Questions