修复子图的点画位置

Fix location of stippling for subplots

我一直在尝试点画等高线图以显示值具有统计显着性的位置。但是,当我在重要性相同的子图中执行此操作时,根据填充点画的随机位置,点画看起来会有所不同。我已经重现了下面的问题。有没有办法固定点画的位置,使它们在绘制时看起来一样?还是有更好的点画方式?

这 2 个子图绘制的数据完全相同,但点画看起来不同。

import numpy as np
from matplotlib import pyplot as plt

#Create some random data
x = np.arange(0,100,1)
x,y = np.meshgrid(x,x)
stipp = 10*np.random.rand(len(x),len(x))

fig =plt.figure(figsize=(12,8))
ax1 = plt.subplot(121)
ax2 = plt.subplot(122)

#Plot stippling 
ax1.contourf(x,y,stipp,[0,4],colors='none',hatches='.')
ax2.contourf(x,y,stipp,[0,4],colors='none',hatches='.')
plt.show()

所以如果有人想知道,点画具有相似统计意义的多个子图的最佳方法是使用上面推荐的散点图而不是等高线图。只需确保对数据进行少量采样,这样就不会出现彼此相邻的高密度点。

import numpy as np
from matplotlib  import pyplot as plt

#Create some random data
x = np.arange(0,100,1)
x,y = np.meshgrid(x,x)
stipp = 10*np.random.rand(len(x),len(x))

fig =plt.figure(figsize=(12,8))
ax1 = plt.subplot(121)
ax2 = plt.subplot(122)

#Plot stippling 
ax1.scatter(x[(stipp<=4) & (stipp>=0)][::5],y[(stipp<=4) & (stipp>=0)][::5])
ax2.scatter(x[(stipp<=4) & (stipp>=0)][::5],y[(stipp<=4) & (stipp>=0)][::5])

plt.show()