简体   繁体   English

Matplotlib:子图

[英]Matplotlib: subplot

I have several time series signals (8x8) that I would like to plot using subplot. 我想使用子图绘制几个时间序列信号(8x8)。 My data are stored in a matrix called H(x, y, N) where N is the number of points in each signal. 我的数据存储在称为H(x,y,N)的矩阵中,其中N是每个信号中的点数。 I would like to display the 64 signals using subplots. 我想使用子图显示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,:])

What I get is 8 signals in the first row, 4 in the second one, then 2, 2, 1, 1, 1 and 1. 我得到的是第一行中的8个信号,第二行中的4个信号,然后是2、2、1、1、1、1和1。

That's not how subplot indexing works. 这不是subplot索引的工作方式。 From the docs to subplot : 文档到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. 其中使用nrows和ncols从概念上将图形拆分为nrows * ncols子轴,并使用plot_number标识此函数将在名义网格中创建的特定子图。 plot_number starts at 1, increments across rows first and has a maximum of nrows * ncols . plot_number从1开始,首先跨行递增,最大为nrows * ncols

So, you want to have nrows=8 , ncols=8 and then a plot_number in the range 1-64, so something like: 因此,您希望nrows=8ncols=8 ,然后是plot_number ,范围为1-64,所以类似:

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([])

To remove tick labels, use gca() to get the current axes, and the set the xticklabels and yticklabels to an empty list: [] 要删除刻度标签,请使用gca()获取当前轴,并将xticklabelsyticklabels设置为空列表: []

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM