python - 2D 核密度 e.在 python 中 - x 轴拥挤并缩小

标签 python numpy matplotlib kernel-density probability-density

我有一个 x,y 点分布,我通过 scipy.stats.gaussian_kde 获取其 KDE。

kmsmins 都是一个包含浮点值的列表,表示跑完公里数所需的时间。

这些值分布在:

  • 分钟:[3.48996296296 - 317.678638298]
  • 公里:[0.180707205317 - 8086.94362983]

在结果中,我将得到一条又高又窄的线——y 值正常显示,但 x 轴非常窄且缩小(刻度线重叠)。有人能指出如何进一步拉伸(stretch) x 轴吗?

这是我生成绘图的代码:

xmin = min(mins)
xmax = max(mins)
ymin = min(kms)
ymax = max(kms)

X, Y = np.mgrid[xmin:xmax:1000j, ymin:ymax:100j]
positions = np.vstack([X.ravel(), Y.ravel()])
values = np.vstack([mins, kms])
kernel = stats.gaussian_kde(values)
Z = np.reshape(kernel(positions).T, X.shape)

fig = plt.figure()
ax = fig.add_subplot(111)
ax.imshow(np.rot90(Z), cmap=plt.cm.gist_earth_r, extent=[xmin, xmax, ymin, ymax])
ax.plot(mins, kms, 'k.', markersize=2)
ax.set_xlim([xmin, 200])
ax.set_ylim([ymin, ymax])

plt.show()

这是情节本身:

enter image description here

最佳答案

您可以通过以下方式将绘图的纵横比从 1:1 更改为自动

ax.axis('正常')

关于python - 2D 核密度 e.在 python 中 - x 轴拥挤并缩小,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19457140/

相关文章:

python - 对打开文件的脚本进行单元测试

python /数巴 : Trouble creating custom type using Numba Extension API

python - 查找一个数据集中的数据在另一数据集中的对应关系

python - 使用 python3.x 在 numpy 中进行楼层划分的 ufunc 是什么?

对具有时间戳的函数进行 Python 单元测试

python - SQLAlchemy 中的按位运算符

python - 以图形方式显示具体范围

python - 如何在单个图中为不同的图获得不同的颜色线

python - 如何在 Python 3 中向 matplotlib 2.0 `ax` 对象添加黑色边框?

python - 如何编写一个看起来像每个 function_name 都有函数名称和变量参数列表的函数