I have some 2D matplotlib plots that have an area of no data below a certain value, as shown below (below the ~1.2 km line on the y-axis):
It seems that matplotlib automatically colors the area of no data with the color used for 0 on the colorbar scale. I feel like I've tried everything - masking the data, using set_under, etc. ....but none of it seems to be working. Here is where I'm at currently:
temperatures = ds_object['temperature'].values
time = ds_object['time'].values
inp_conc = ds_object['n_inp_stp'].values
vmin = 0.0
vmax = np.amax(inp_conc)
bad_color = 'lightgray'
cmap = cm.jet
cmap.set_under(color=bad_color)
mesh = display.fig.axes[0].pcolormesh(xrng,temperatures,inp_conc.transpose(),cmap=cmap,
vmin=vmin, vmax=vmax)
fig = display.fig
ax = fig.axes[0]
ax.set_ylabel('Freezing Temperature (degC)')
ax.set_title(f"{datastream} {ds_object['n_inp_stp'].attrs['long_name']} on {date}")
myFmt = mdates.DateFormatter('%H:%M')
ax.xaxis.set_major_formatter(myFmt)
# Give the colorbar it's own axis so the 2D plots line up with 1D
box = ax.get_position()
pad, width = 0.01, 0.01
cax = fig.add_axes([box.xmax + pad, box.ymin, width, box.height])
cbar = plt.colorbar(mesh, cax=cax)
#get n_inp_stp min and max for colorbar
n_inp_stp = ds_object['n_inp_stp'].values
maximum = np.nanmax(n_inp_stp)
minimum = np.nanmin(n_inp_stp)
mesh.set_clim(minimum,maximum) # set colorbar range
cbar.ax.set_ylabel('Number of INP per L of air at STP (count/L)', rotation=270, fontsize=8, labelpad=8)
cbar.ax.tick_params(labelsize=6)
cbar.ax.set_yscale('log')
But for some reason, using the set_color hasn't been working. Does anyone have any idea as to what I'm doing wrong?