答案 0 :(得分:1)
您可以在等高线图的顶部使用pcolormesh,使其隐藏在其下方的区域。
import matplotlib.pyplot as plt
import numpy as np
x = np.linspace(-120.,120.,13)
X,Y = np.meshgrid(x,x)
Z = X*np.sqrt(np.abs(Y))*np.exp(-(X**2+Y**2)/3000.)
Xf = X.flatten()
Yf = Y.flatten()
Zf = Z.flatten()
cond = Xf**2+Yf**2 < 105**2
Xf = Xf[cond]
Yf = Yf[cond]
Zf = Zf[cond]
cond2 = X**2+Y**2 < 105**2
mask = np.zeros_like(X)
mask = np.ma.masked_array(mask,mask=cond2)
fig, ax = plt.subplots()
ax.tricontourf(Xf,Yf,Zf, levels=np.linspace(Z.min(), Z.max(), 10))
dx=np.diff(X[0,:])[0]; dy=np.diff(Y[:,0])[0]
ax.pcolormesh(X,Y,mask, zorder=2, cmap="gray", vmin=-1)
ax.pcolormesh(X-dx,Y-dy,mask, zorder=2, cmap="gray", vmin=-1)
ax.pcolormesh(X,Y-dy,mask, zorder=2, cmap="gray", vmin=-1)
ax.pcolormesh(X-dx,Y,mask, zorder=2, cmap="gray", vmin=-1)
ax.scatter(Xf,Yf, c="k", s=5, zorder=3)
plt.show()
答案 1 :(得分:0)
这是一种黑客行为,但我认为你可以绘制黑色边框矩形大小的填充白色矩形,以隐藏这些位置的等高线图。