N1B4
N1B4

Reputation: 3453

Adjust right margin width to fit margin text

I am creating a figure that has text in the right margin, but that text is being cut off in the figure. I have tried adjusting figsize, but to no avail. Is there a way to increase the right margin width so that all margin text is visible?

models = ['GISS-E2-H', 'MRI-CGCM3', 'bcc-csm1-1-m', 'IPSL-CM5A-LR', \
         'CanESM2', 'CESM1-BGC', 'IPSL-CM5B-LR', 'inmcm4', 'GISS-E2-R',\
         'IPSL-CM5A-MR', 'MPI-ESM-MR', 'GFDL-CM3', 'CCSM4', 'bcc-csm1-1',\
         'NorESM1-M', 'GFDL-ESM2M', 'CESM1-CAM5', 'HadGEM2-ES', \
         'CSIRO-Mk3-6-0', 'CNRM-CM5', 'ACCESS1-3', 'CMCC-CESM', 'CMCC-CMS',\
         'NorESM1-ME', 'MPI-ESM-LR', 'ACCESS1-0', 'BNU-ESM', 'MIROC5', \
         'CMCC-CM', 'EC-EARTH', 'GFDL-ESM2G', 'MIROC-ESM', 'MIROC-ESM-CHEM',\
         'FGOALS-g2']

for idx, model in enumerate(models):
    # Plot the marker as the model number
    plt.text(stdv_changes[idx], mean_changes[idx], str(idx+1), fontsize=12)

    # Add right margin text (model number - model)
    y_loc = .9 - (1./40.)*int(idx)
    plt.figtext(.925, y_loc, '{0:2d} - {1}'.format(idx+1, models[idx]), fontsize=8)

plt.ylim(-10,15)
plt.xlim(-5,10)
plt.axvline(linewidth=.25, linestyle='dashed', color='black')
plt.axhline(linewidth=.25, linestyle='dashed', color='black')
plt.xlabel('Standard deviation change (cm)')
plt.ylabel('Mean change (cm)')
plt.show()

enter image description here

Upvotes: 0

Views: 607

Answers (1)

Primer
Primer

Reputation: 10302

Have a look at this question. You could do this just before calling plt.show():

plt.subplots_adjust(right=.8) # or even smaller number to shift the right edge to the left

Upvotes: 2

Related Questions