Matplotlib:子图 [英] Matplotlib: subplot
问题描述
我有几个要使用子图绘制的时间序列信号(8x8).我的数据存储在称为H(x,y,N)的矩阵中,其中N是每个信号中的点数.我想使用子图显示64个信号.
I have several time series signals (8x8) that I would like to plot using subplot. My data are stored in a matrix called H(x, y, N) where N is the number of points in each signal. I would like to display the 64 signals using subplots.
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.
What I get is 8 signals in the first row, 4 in the second one, then 2, 2, 1, 1, 1 and 1.
推荐答案
这不是subplot
索引的工作方式.从文档到subplot
:
That's not how subplot
indexing works. From the docs to subplot
:
subplot(nrows, ncols, plot_number)
其中nrows和ncols用于将图形名义上划分为nrows * ncols
子轴,而 plot_number 用于标识此函数将在名义网格中创建的特定子图. plot_number 从1开始,首先跨行递增,最大值为nrows * ncols
.
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 of nrows * ncols
.
因此,您想要具有nrows=8
,ncols=8
,然后是一个范围为1-64的plot_number
,如下所示:
So, you want to have nrows=8
, ncols=8
and then a plot_number
in the range 1-64, so something like:
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
设置为空列表:[]
To remove tick labels, use gca()
to get the current axes, and the set the xticklabels
and yticklabels
to an empty list: []
这篇关于Matplotlib:子图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!