Matplotlib:子图 [英] Matplotlib: subplot

查看:99
本文介绍了Matplotlib:子图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个要使用子图绘制的时间序列信号(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=8ncols=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()获取当前轴,并将xticklabelsyticklabels设置为空列表:[]

To remove tick labels, use gca() to get the current axes, and the set the xticklabels and yticklabels to an empty list: []

这篇关于Matplotlib:子图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆