gpt4 book ai didi

Python - 从不同长度的向量绘制二维概率分布

转载 作者:太空宇宙 更新时间:2023-11-04 08:51:48 24 4
gpt4 key购买 nike

我有两个不同长度的向量及其对应的概率。

import numpy as np

x = np.arange(10)+1
y = np.arange(15)+10
px = np.random.normal(0.5,0.05,10)
py = np.random.normal(0.5,0.05,15)

我想制作一个 x 对 y 的 2D,其中平面根据 x 和 y 的概率着色。

我一直坚持 x 和 y 的维度不同这一事实。但本质上应该只是在 x 和 y 方向上给出不同大小的“像素”,不是吗?任何建议表示赞赏!

最佳答案

你是说这种东西吗? extent=[x0, x1, y0, y1] 是一种覆盖坐标轴比例的方法,可在 this answer 中找到.可能有更好或更好的方法。

import numpy as np
import matplotlib.pyplot as plt


x = np.arange(10)+1
y = np.arange(15)+10
px = np.random.normal(0.5,0.05,10)
py = np.random.normal(0.5,0.05,15)

p = px[None,:]*py[:,None]

plt.figure(figsize=[10,6])

plt.subplot(1,2,1)
plt.imshow(p, origin='lower', extent=[1,10, 10,24])
plt.colorbar()

plt.subplot(1,2,2)
plt.imshow(p, cmap='gray', vmin=0.1, vmax=0.4, interpolation=None,
origin='lower', extent=[1,10, 10,24] )

plt.colorbar()

plt.savefig("twoDp")

plt.show()

enter image description here

关于Python - 从不同长度的向量绘制二维概率分布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34482226/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com