I have a problem where I am plotting a magnitude quantity against wavenumbers, the range of relevant wavenumbers is between 950 - 1300 cm(^-1). However, there are only magnitude datapoints for ranges within the whole wavenumber range, i.e. 950-1000, 1050-1100, 1200-1300 etc. When I plot this using matplotlib, I get large gaps in the plot (after I have inserted 'NANs' in between the datagaps to avoid unwanted extrapolation). I am not sure how to remove these gaps, I want to see a constant lineplot, with the xaxis taking into account the jumps between values. My code is below, along with an example of the plot. In addition the xaxis labels seem to overlap, which I would like to avoid as well.
def plot_radiances(self,index=0):
# method to plot radiances, and residuals and jacobians
wavelength = self.mask_data(self.general_radiance.FREQUENCY.values[:],-999, xarray=False)
observed_radiance = self.mask_data(self.general_radiance.RADIANCEOBSERVED.values[:],-999, xarray=False)
fit_radiance = self.mask_data(self.general_radiance.RADIANCEFIT.values[:],-999, xarray=False)
NESR = self.mask_data(self.general_radiance.NESR.values[:],-999, xarray=False)
quality = np.where(self.general_radiance.QUALITY.values[:] > 0)
wavelength = (wavelength[quality,:][0])
cwavelength = wavelength
observed_radiance = observed_radiance[quality,:][0]
fit_radiance = fit_radiance[quality,:][0]
NESR = NESR[quality,:][0]
dpi = 96.
length = len(quality)
nanind = []
for i,ii in enumerate(wavelength[index,:]):
if float(ii)-float(wavelength[index,i-1]) > 1.0:
nanind.append(i)
wavelength = np.insert(wavelength,nanind,np.nan,axis=1)
observed_radiance = np.insert(observed_radiance,nanind,np.nan,axis=1)
print(wavelength[index,:])
fig = figure(figsize=(800 / dpi , 600 / dpi),dpi=dpi)
ax = axes()
ax.plot(wavelength[index,:],observed_radiance[index,:])
ax.set_xticks(wavelength[index,:][::12])
ax.set_xticklabels([str(i) for i in wavelength[index,:]][::12])
return []