matplotlib中二维直方图上的一维函数

2024-09-27 21:25:37 发布

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

我使用matplotlib以二维直方图的形式绘制一些数据。我的脚本的典型输出如下所示:

Histogram

脚本的相关部分如下:

xbins = 10**np.linspace(-3, 0, 100)
ybins = 10**np.linspace(-3, 0, 100)
counts, _, _ = np.histogram2d(x1val, x2val, bins=(xbins, ybins))
fig, ax = plt.subplots()
mesh = ax.pcolormesh(xbins, ybins, counts)#, norm=LogNorm())
ax.set_xscale('log')
ax.set_yscale('log')
plt.xlabel('$x_1$')
plt.ylabel('$x_2$')
plt.title(title)
plt.colorbar(mesh)

其中x1valx2val是充满数据的列表,我只想在直方图上绘制一条由一些简单的function x2 = f(x1)定义的白色曲线。这有可能吗?你知道吗

最好的, 拉德克


Tags: 数据脚本np绘制pltax直方图set

热门问题