一般来说,matplotlib 中大多数东西的颜色缩放由vmin 和vmax 关键字参数控制。
您必须在字里行间稍加阅读,但正如文档所述,hist2d 中的其他 kwargs 将传递给pcolorfast。因此,您可以通过vmin 和vmax kwargs 指定颜色限制。
例如:
import numpy as np
import matplotlib.pyplot as plt
small_data = np.random.random((2, 10))
large_data = np.random.random((2, 100))
fig, axes = plt.subplots(ncols=2, figsize=(10, 5), sharex=True, sharey=True)
# For consistency's sake, we'll set the bins to be identical
bins = np.linspace(0, 1, 10)
axes[0].hist2d(*small_data, bins=bins, vmin=0, vmax=5)
axes[1].hist2d(*large_data, bins=bins, vmin=0, vmax=5)
plt.show()