我有几个时间序列信号(8x8),我想使用子图来绘制它们。我的数据存储在名为 H(x, y, N) 的矩阵中,其中 N 是每个信号中的点数。我想使用子图显示 64 个信号。
fig = figure(figsize=(12,8))
time = np.arange(0, Nt, 1)
for x in range(8):
for y in range(8):
subplot(8,y+1,x+1)
plot(time,H[x,y,:])
我得到的是第一行有 8 个信号,第二行有 4 个信号,然后是 2、2、1、1、1 和 1。
最佳答案
这不是 subplot
索引的工作原理。来自 docs to subplot
:
subplot(nrows, ncols, plot_number)
Where nrows and ncols are used to notionally split the figure into
nrows * ncols
sub-axes, and plot_number is used to identify the particular subplot that this function is to create within the notional grid. plot_number starts at 1, increments across rows first and has a maximum ofnrows * ncols
.
因此,您希望有 nrows=8
、ncols=8
以及 1-64 范围内的 plot_number
,所以像:
nrows,ncols = 8,8
for y in range(8):
for x in range(8):
plot_number = 8*y + x + 1
subplot(nrows,ncols,plot_number)
plot(time,H[x,y,:])
# Remove tick labels if not on the bottom/left of the grid
if y<7: gca().set_xticklabels([])
if x>0: gca().set_yticklabels([])
要删除刻度标签,请使用 gca()
获取当前坐标区,并将 xticklabels
和 yticklabels
设置为空列表:[]
关于python - Matplotlib:子图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35510155/