我有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()
但是由于这只能给出20x20的直方图,所以我不知道强度在输出图中如何分布(例如,大致零中心),也不知道如何固定刻度。
答案 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()
输出:
答案 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()
输出:
答案 2 :(得分:0)