Created
May 3, 2017 10:30
-
-
Save lucgiffon/cd12542bedaf971a20fdb8c2466c0c5c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def mpl_layout(rows_cols, axis=0): | |
""" | |
Description: | |
------------ | |
Prepare matplotlib layout for complexe layouts. | |
Exemple: | |
-------- | |
If you have done 6 independant experiences with graphes but you want to show them all in one figure with 2 graphes on each row | |
and 3 rows of graphes. Moreover, you want to display the graphes by lines, eg: on each row, you want 2 consecutive experiences. | |
In this case, you use the axis parameter at 0. | |
Usage: | |
------ | |
>>> mpl_layout((2, 3)) | |
[(0, 0), (0, 1), (0, 2), (1, 0), (1, 1), (1, 2)] | |
>>> mpl_layout((3, 2)) | |
[(0, 0), (1, 0), (2, 0), (0, 1), (1, 1), (2, 1)] | |
""" | |
assert type(rows_cols) == tuple and len(rows_cols) == 2 | |
assert axis == 0 or axis == 1 | |
position = [] | |
rows = rows_cols[0] | |
cols = rows_cols[1] | |
if axis == 0: | |
for i in range(rows): | |
for j in range(cols): | |
position.append((i, j)) | |
else: | |
for j in range(cols): | |
for i in range(rows): | |
position.append((i, j)) | |
return position |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment