python - 多个时间序列的 Matplotlib 热图显示随时间的分布

标签 python numpy matplotlib time-series

我有 n_series 记录具有相同的帧 0, 1, 2, 3,... 并且想从中制作一个 2D 轮廓。

我发现我可以很容易地做到以下几点:

import matplotlib.pyplot as plt
import numpy as np

series_len = 1000
n_series = 10

y = np.random.normal(0, 0.15, series_len * n_series)
x = np.tile(np.arange(0, series_len, 1), n_series)

heatmap, xbins, ybins = np.histogram2d(x, y, bins=20)

plt.contourf(heatmap.T)
plt.show()

enter image description here

但是因为这只是给出了一个 20x20 的直方图,我不知道我的强度在输出图中是如何分布的(例如大致以零为中心),也不知道如何修复刻度。

我想要的是这个('已购买): enter image description here

最佳答案

尝试set_xticklabels:

series_len = 1000
n_series = 10

fig, ax = plt.subplots(figsize=(10,6))
np.random.seed(1)
y = np.random.normal(0, 0.15, series_len * n_series)
x = np.tile(np.arange(0, series_len, 1), n_series)

heatmap, xs, ys = np.histogram2d(x, y, bins=20)

fig, ax = plt.subplots(figsize=(10,6))
ax.contourf(heatmap.T)

# the actual x-axis and y-axis are from 0 to 19
# we want to put 11 ticks on the axis
ax.set_xticks(np.linspace(0,19,11))
ax.set_xticklabels(range(0,1001,100))

ax.set_yticks(np.linspace(0,19,11))
ax.set_yticklabels(['{:.3f}'.format(y) for y in ys[::2]])

plt.show()

输出:

enter image description here

关于python - 多个时间序列的 Matplotlib 热图显示随时间的分布,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56361103/

相关文章:

python - Google App Engine for Python 中的引用文献列表

python - 非线性 pyplot imshow 颜色

python - 将多个值添加到一个 numpy 数组索引

Python - 读取具有不同分隔符的数据文本文件

Python plot - 堆叠图像切片

python - pandas .diff 按行的多索引值

python - Tweepy 在使用 Twitter API v2 方法时不返回 url 媒体字段

python - 使用 numpy.take 类型转换错误

python - matplotlib 调整图像大小

python - 对数图中的负轴