I am trying to make a contour plot from some data files. The trouble I am having is that I want the z-values below the minimum on the color bar to be the same color as the minimum value.
This is easy when using a linear scale using e.g. the extend="both"
option for the contourf
, or using cmap.set_under()
for the colormap. Unfortunately neither of those options work when using a logscale. Can anyone suggest a workaround? I just want to get rid of the white areas in the plot below:
#!/usr/bin/env python
import numpy as np
import matplotlib.pyplot as plt
import scipy.interpolate
from matplotlib import colors, ticker, cm
from matplotlib.colors import LogNorm
N = 100 #number of points for plotting/interpolation
y, x, z = np.genfromtxt(r'40Ca_208Pb_39K_Ex_115deg.dat', unpack=True)
xi = np.linspace(x.min(), x.max(), N)
yi = np.linspace(y.min(), y.max(), N)
zi = scipy.interpolate.griddata((x, y), z, (xi[None,:], yi[:,None]), method='linear')
hfont = {'fontname':'Palatino'}
fig = plt.figure(facecolor="white")
zi = np.ma.masked_less(zi, 1e-7)
plt.contourf(xi, yi, zi,levels=[1e-7,1e-6,1e-5,1e-4,1e-3,1e-2,1e-1],cmap=plt.cm.jet,norm = LogNorm())
plt.xlabel("$E_{x}$")
plt.ylabel("$E/V_{B}$")
plt.colorbar()
plt.show()
set_under
is not working properly you need to provide a minimal reproducible example of the issue. Here you just mask the array to be plotted, so the masked parts are simply not plotted at all. You cannot set any color to something which isn't plotted. On the other hand you may simply change the background color of the axes to the color of your liking. – ImportanceOfBeingErnest Dec 3 '17 at 11:19