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()
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…