Matplotlib热图用于多个时间序列以显示时间分布

时间:2019-05-29 12:50:22

标签: 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

3 个答案:

答案 0 :(得分:2)

尝试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

答案 1 :(得分:1)

IIUC,您想要这样的东西吗?

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, xlabels, ylabels = np.histogram2d(x, y, bins=20)

plt.contourf(xlabels[:-1], ylabels[:-1], heatmap.T)
plt.colorbar()
plt.show()

输出:

enter image description here

答案 2 :(得分:0)

好吧,我自己找到了一个答案,这使得该过程比看起来简单得多。只需使用--reference-doc=FILE Use the specified file as a style reference in producing a docx or ODT file. ... 在两个方向上将热图的大小都按1调整,即可使所有操作顺利进行。

skimage

enter image description here