python 中是否有一个函数来填充由不同函数给出的两条等高线之间的区域?
Is there a function in python to fill the area between two contourlines each given by different functions?
如果我有两条等高线
plt.contourf(xx, yy, zzmax, levels=[1], colors='r', alpha=0.8)
plt.contourf(xx, yy, zzmin, levels=[1], colors='r', alpha=0.8)
如何绘制填充它们之间区域的域?
(抱歉,如果这是一个菜鸟问题)
以下代码首先创建一些测试数据。蓝线表示 zzmax
和 zzmin
等于 1
。右侧的子图以红色显示 zzmax
小于 1 且 zzmin
大于 1 的区域。
from matplotlib import pyplot as plt
from matplotlib.colors import ListedColormap
import numpy as np
from scipy.ndimage import gaussian_filter
xx = np.linspace(0, 10, 100)
yy = np.linspace(0, 8, 80)
np.random.seed(11235813)
zzmax = gaussian_filter(np.random.randn(len(yy), len(xx)) * 10 + 1, 8)
zzmin = gaussian_filter(np.random.randn(len(yy), len(xx)) * 10 + 0.9, 8)
fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(15, 4))
cnt1 = ax1.contourf(xx, yy, zzmax, cmap='RdYlGn')
plt.colorbar(cnt1, ax=ax1)
ax1.contour(xx, yy, zzmax, levels=[1], colors='skyblue', linewidths=3)
ax1.set_title('zzmax')
cnt2 = ax2.contourf(xx, yy, zzmin, cmap='RdYlGn')
plt.colorbar(cnt2, ax=ax2)
ax2.contour(xx, yy, zzmin, levels=[1], colors='skyblue', linewidths=3)
ax2.set_title('zzmin')
ax3.contourf(xx, yy, (zzmax <= 1) & (zzmin >= 1), levels=[0.5, 2], cmap=ListedColormap(['red']), alpha=0.3)
ax3.set_title('zzmax ≤ 1 and zmin ≥ 1')
plt.tight_layout()
plt.show()
如果我有两条等高线
plt.contourf(xx, yy, zzmax, levels=[1], colors='r', alpha=0.8)
plt.contourf(xx, yy, zzmin, levels=[1], colors='r', alpha=0.8)
如何绘制填充它们之间区域的域?
(抱歉,如果这是一个菜鸟问题)
以下代码首先创建一些测试数据。蓝线表示 zzmax
和 zzmin
等于 1
。右侧的子图以红色显示 zzmax
小于 1 且 zzmin
大于 1 的区域。
from matplotlib import pyplot as plt
from matplotlib.colors import ListedColormap
import numpy as np
from scipy.ndimage import gaussian_filter
xx = np.linspace(0, 10, 100)
yy = np.linspace(0, 8, 80)
np.random.seed(11235813)
zzmax = gaussian_filter(np.random.randn(len(yy), len(xx)) * 10 + 1, 8)
zzmin = gaussian_filter(np.random.randn(len(yy), len(xx)) * 10 + 0.9, 8)
fig, (ax1, ax2, ax3) = plt.subplots(ncols=3, figsize=(15, 4))
cnt1 = ax1.contourf(xx, yy, zzmax, cmap='RdYlGn')
plt.colorbar(cnt1, ax=ax1)
ax1.contour(xx, yy, zzmax, levels=[1], colors='skyblue', linewidths=3)
ax1.set_title('zzmax')
cnt2 = ax2.contourf(xx, yy, zzmin, cmap='RdYlGn')
plt.colorbar(cnt2, ax=ax2)
ax2.contour(xx, yy, zzmin, levels=[1], colors='skyblue', linewidths=3)
ax2.set_title('zzmin')
ax3.contourf(xx, yy, (zzmax <= 1) & (zzmin >= 1), levels=[0.5, 2], cmap=ListedColormap(['red']), alpha=0.3)
ax3.set_title('zzmax ≤ 1 and zmin ≥ 1')
plt.tight_layout()
plt.show()