自动化次要情节的填充 [英] Automate the Populating of Subplots

查看:180
本文介绍了自动化次要情节的填充的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一个python脚本,将(1)得到的y值的列表,每个插曲暗算一套共同的x值的过程中,(2)使这些次要情节一个散射 - 中情节并把它放在适当的位置,在副区电网,以及(3)完成这些任务对于不同尺寸的插曲网格。我的意思第三条语句是这样的:测试案例我用了64个地块,8行8列的数组结果。我想为code到能够处理任何大小的数组各种网格尺寸(约50和80地块之间)没有我不得不回去我每次运行code和说:好吧时间,这里的行,我需要的列数。

I am in the process of writing a python script that will (1) obtain a list of y-values for each subplot to plot against a common set of x-values, (2) make each of these subplots a scatter-plot and put it in the appropriate location in the subplot grid, and (3) complete these tasks for different sizes of subplot grids. What I mean by the third statement is this: the test case I'm using results in an array of 64 plots, 8 rows and 8 columns. I would like for the code to be able to handle any size array (roughly between 50 and 80 plots) for various grid dimensions without me having to go back in each time I run the code and say "Okay, here's the number of rows and columns I need."

现在,我使用exec命令来获取y值,而这工作的罚款。我能够让每一个次要情节,并得到它来填充网格,但只有当我用手(做同样的事情的64倍输入的一切仅仅是哑巴,所以我知道一定是自动化的方式这个)。

Right now, I'm using an exec command to obtain the y-values, and that's working fine. I'm able to make each of the subplots and get it to populate the grid, but only if I type everything in by hand (64 times of doing the same thing is just dumb, so I know there's got to be a way to automate this).

任何人都可以提出一个方法中,这可能实现呢?我不能提供数据或我的code,因为这是研究材料而不是我释放。如果这个问题是非常基本的或者是什么,我应该能够从现有的文档,以确定请原谅我。我很新的节目,并可以用一些指导!

Could anyone suggest a way in which this might be accomplished? I cannot provide data or my code, as this is research material and is not mine to release. Please excuse me if this question is very basic or is something that I should be able to determine from existing documentation. I am very new to programming, and could use a little guidance!

推荐答案

这样的事情一个有用的功能是 plt.subplots(NROWS,NCOLS)它会返回一个阵列的次要情节的定期格(一个numpy的对象数组)。

A useful function for things like this is plt.subplots(nrows, ncols) which will return an array (a numpy object array) of subplots on a regular grid.

作为一个例子:

import matplotlib.pyplot as plt
import numpy as np

fig, axes = plt.subplots(nrows=4, ncols=4, sharex=True, sharey=True)

# "axes" is a 2D array of axes objects.  You can index it as axes[i,j] 
# or iterate over all items with axes.flat

# Plot on all axes
for ax in axes.flat:
    x, y = 10 * np.random.random((2, 20))
    colors = np.random.random((20, 3))
    ax.scatter(x, y, s=80, facecolors=colors, edgecolors='')
    ax.set(xticks=np.linspace(0, 10, 6), yticks=np.linspace(0, 10, 6))

# Operate on just the top row of axes:
for ax, label in zip(axes[0, :], ['A', 'B', 'C', 'D']):
    ax.set_title(label, size=20)

# Operate on just the first column of axes:
for ax, label in zip(axes[:, 0], ['E', 'F', 'G', 'H']):
    ax.set_ylabel(label, size=20)

plt.show()

这篇关于自动化次要情节的填充的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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