-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Revamp tls.get_subplots #170
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
9b2f4c0
637c5de
55637e0
1b1d23a
76c6d4e
9f1c240
5406fb3
26f704e
d9341c8
8705058
842ff88
c55a92f
34ee502
97145a5
5dfcfad
f72a249
857a7d7
e64794b
ab661f4
eced9a3
55a9b3f
3eba0d7
79c9868
ca08227
4efbb4f
69214c6
0497009
a83ad48
2d781f6
b8e9f53
46ed9d7
540b734
7b0e8fb
f6a64d1
bed60db
50eeb8f
1a2192e
443217e
a72f043
8e3e83d
d30e7b9
f9235b3
dfa47f7
3ef8116
ec25258
25c8d85
330eeac
12cdffd
e52ff4f
bad84cd
0c83b9d
45229d2
fa286a0
f0c3997
feea0cc
98b955f
e5d753f
0d74fb3
6df366e
5bcbaaa
2edb810
421dd5f
af67e90
7bb6ba2
67672dd
a311719
dd16fa2
254cf13
46b6c73
4a6b718
1cb0026
964daff
7463f60
f0eea15
95cded8
7b0e5d1
3f7572a
e9c2e01
bfa69ce
0f75a2d
9c34d84
d39a0be
87d645a
08892a9
e4d4936
2de9ad7
bd16672
6b2465b
0437513
9a2767b
f13a408
857013c
7e2d3e0
ff0a112
8dc3f80
87501d8
cebfae2
68aee36
4ee9b59
d2d7a92
1f1960d
e0301ad
3ac711f
5536194
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -387,8 +387,7 @@ def mpl_to_plotly(fig, resize=False, strip_style=False, verbose=False): | |
### graph_objs related tools ### | ||
|
||
# TODO: Scale spacing based on number of plots and figure size | ||
def get_subplots(rows=1, columns=1, horizontal_spacing=0.1, | ||
vertical_spacing=0.15, print_grid=False): | ||
def get_subplots(*arg, **kwargs): | ||
"""Return a dictionary instance with the subplots set in 'layout'. | ||
|
||
Example 1: | ||
|
@@ -401,25 +400,73 @@ def get_subplots(rows=1, columns=1, horizontal_spacing=0.1, | |
# print out string showing the subplot grid you've put in the layout | ||
fig = tools.get_subplots(rows=3, columns=2, print_grid=True) | ||
|
||
key (types, default=default): | ||
description. | ||
fig (arg[0]): | ||
Plotly figure object or dictionary. | ||
|
||
rows (int, default=1): | ||
Number of rows, evenly spaced vertically on the figure. | ||
By default, get_subplots add keys 'xaxis[1-9]' and 'yaxis [1-9]' | ||
to fig['layout'] | ||
|
||
columns (int, default=1): | ||
Number of columns, evenly spaced horizontally on the figure. | ||
If fig['data'] contains ONLY 3D traces, get_subplots add keys | ||
'scene[1-9]' to fig['layout'] | ||
|
||
horizontal_spacing (float in [0,1], default=0.1): | ||
Space between subplot columns. Applied to all columns. | ||
rows (kwarg, int, default=1): | ||
Number of rows on the figure. | ||
|
||
vertical_spacing (float in [0,1], default=0.05): | ||
Space between subplot rows. Applied to all rows. | ||
columns (kwarg, int, default=1): | ||
Number of columns on the figure. | ||
|
||
print_grid (True | False, default=False): | ||
If True, prints a tab-delimited string representation of your plot grid. | ||
arrangements (kwarg, list or list of lists, default=[]): | ||
Subplot arrangement as a list (or list of lists) of subplot indices. | ||
Overrides the 'rows' and 'columns' arguments. | ||
|
||
Use integers 1, 2, ... for 2d subplots. | ||
Use 'scene1', 'scene2', ... for 3d subscenes. | ||
|
||
The x-domain of each subplot i is given by: | ||
|
||
number of index i in row / total number of indices in row | ||
|
||
The y-domain of each subplot is given by: | ||
|
||
number of index i in column / total number of indices in column | ||
|
||
ex1: [[1, 2, 3], [4, 5], [6]] | ||
ex2: [[1], [1, 2], [1, 3]] | ||
ex3: [1, 'scene1'] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. e.g. the subplot grid of https://plot.ly/~etpinard/245 could be generated with
Oops I just realized that the actually formula would have to be more complicated than what I wrote, but definitely doable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we can think of a good way to expose inset subplots here, then I'm for it :) I think subplots are difficult enough to setup for complicated cases that this would be pretty helpful. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @etpinard , i think i've mentioned this before. but i really like how gridspec from matplotlib handles this stuff: http://matplotlib.org/users/gridspec.html With this approach, you just let the user define a rectangular grid, and then assign graphs to locations on that grid. |
||
|
||
horizontal_spacing (kwarg, float in [0,1] or list, default=0.1): | ||
Space between subplot columns. | ||
Applied to all columns if float. | ||
Applied to per column from left to right if list. | ||
Applied to per column from left to right and per row from bottom to top | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. per subplot horizontal and vertical spacing. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yup. this should be easier to customize for sure. |
||
if list of lists. | ||
|
||
vertical_spacing (kwarg, float in [0,1] or list, default=0.05): | ||
Space between subplot rows. | ||
Applied to all rows if float. | ||
Applied to per row from bottom to top if list. | ||
Applied to per row from bottom to top and per column from left to right | ||
if list of lists. | ||
|
||
shared_xaxes (kwarg, boolean or list, default=False) | ||
Assign shared x axes. | ||
If True, share all x axes. | ||
If list of booleans, share all x axes per column from left to right. | ||
If list of integers, share x axes per subplot index, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. together with the indices in There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is cool, yeah. |
||
set in 'arrangement'. | ||
|
||
shared_yaxes (kwarg, boolean or list, default=False) | ||
Assign shared y axes. | ||
If True, share all y axes. | ||
If list of booleans, share all y axes per row from left to right. | ||
If list of integers, share y axes per subplot index, | ||
set in 'arrangement'. | ||
|
||
print_grid (kwarg, boolean, default=False): | ||
If True, prints a tab-delimited string representation of | ||
your plot grid. | ||
""" | ||
|
||
fig = dict(layout=graph_objs.Layout()) # will return this at the end | ||
plot_width = (1 - horizontal_spacing * (columns - 1)) / columns | ||
plot_height = (1 - vertical_spacing * (rows - 1)) / rows | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm thinking about supporting
fig = tls.get_subplots(fig, **kwargs)
e.g. if someone wants to augment a already-defined figure object.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i maybe it would make sense as as a method of a figure?