I would like to plot a series of contour lines, but the spacing between where the label is and the line increases higher up the page. I've plotted an example attached. I want no decimal points, hence used fmt, but this seems to change the spacing at different points (Ideally I want around half a centimetre gap between the contour line break and the writing.
As an aside, I also tried to use the manual locations so it'd plot each label at a certain place, but as there are two seperate contour lines with the same value I'm not sure if this is possible. Thanks!
Here is my code;
from netCDF4 import Dataset
import numpy as np
from matplotlib import pyplot as plt
#############################
# #
# Parameter Setup #
# #
#############################
myfile = '/home/ubuntu/Documents/Control/puma/run/Control.nc' #Control U
myfile2 = '/home/ubuntu/Documents/Control_Trop_40K/puma/run/ControlTrop.nc' #Perturbed U
Title = 'U'
Units = '!U'
Variable = 'ua'
#############################
#############################
Import = Dataset(myfile, mode='r')
Import2 = Dataset(myfile2, more='r')
latt = Import.variables['lat'][:]
level = Import.variables['lev'][:]
UControl = Import.variables[Variable][:]
#UPerturbed = Import2.variables[Variable][:]
#UChange = UPerturbed - UControl
#UChange = np.mean(UChange[:,:,:,0], axis=0)
UControl = np.mean(UControl[:,:,:,0], axis=0)
Contourrange = [10]
CS=plt.contour(latt,level,UControl,Contourrange, colors='k')
plt.clabel(CS, fontsize=10, inline=1,fmt = '%1.0f',ticks=Contourrange)
plt.gca().invert_yaxis()
plt.yscale('log', nonposy='clip')
plt.xticks(np.round((np.arange(-90, 91, 30)), 2))
plt.xlim(xmin=-90)
plt.yticks([900,800,700,600,500,400,300,200,100,50])
plt.gca().set_yticklabels([900,800,700,600,500,400,300,200,100,50])
plt.xlabel('Latitude')
plt.ylabel('Pressure (hPa)')
plt.title(Title)
plt.show()
The pictures are:


inline_spacingargument toplt.clabel? I think this controls what you're trying to do. - farenorth