确定子图点画的位置

2024-06-16 14:53:31 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在试着点画等高线图,以显示数值在统计上有显著意义的位置。然而,当我在意义相同的子图中这样做时,点画看起来会根据填充点画的随机位置而不同。我复制了下面的问题。有没有办法确定点画的位置,使它们在绘制时看起来一样?或者有没有更好的方法来画点图?在

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

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()

enter image description here


Tags: importlenasnp绘制pltrandom意义
1条回答
网友
1楼 · 发布于 2024-06-16 14:53:31

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

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()

enter image description here

相关问题 更多 >