Skip to content

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

Merged
merged 104 commits into from
Jan 13, 2015
Merged
Changes from 1 commit
Commits
Show all changes
104 commits
Select commit Hold shift + click to select a range
9b2f4c0
add specs to revamped get_subplots()
etpinard Dec 22, 2014
637c5de
sync latest graph ref master
etpinard Dec 29, 2014
55637e0
update get_subplots() docstring
etpinard Dec 30, 2014
1b1d23a
remove old get_subplots() code
etpinard Dec 30, 2014
76c6d4e
add Exception if rows or/and columns are not integers
etpinard Dec 30, 2014
9f1c240
make h/v spacing depend on the number of rows/columns:
etpinard Dec 30, 2014
5406fb3
initialize specs list of lists:
etpinard Dec 30, 2014
26f704e
compute some common distances
etpinard Dec 30, 2014
d9341c8
loop through specs:
etpinard Dec 30, 2014
8705058
add _get_shared()
etpinard Dec 30, 2014
842ff88
add _add_domain() and _add_domain_is3D()
etpinard Dec 30, 2014
c55a92f
add _fill_grid()
etpinard Dec 30, 2014
34ee502
initialize looping variables
etpinard Dec 30, 2014
97145a5
(oops) get_shared -> _get_shared
etpinard Dec 30, 2014
5dfcfad
add print_grid
etpinard Dec 30, 2014
f72a249
modify computed domain in existing tests (because of rounding errors)
etpinard Dec 30, 2014
857a7d7
modify arguments in existing tests:
etpinard Dec 30, 2014
e64794b
test galore git diff --cached !
etpinard Dec 30, 2014
ab661f4
improve algorithm (part 1):
etpinard Dec 31, 2014
eced9a3
improve algorithm (part 2):
etpinard Dec 31, 2014
55a9b3f
improve algorithm (part 3):
etpinard Dec 31, 2014
3eba0d7
improve algorithm (part 4):
etpinard Dec 31, 2014
79c9868
improve algorthm (part 5):
etpinard Dec 31, 2014
ca08227
remove _get_shared()
etpinard Dec 31, 2014
4efbb4f
add _get_label()
etpinard Dec 31, 2014
69214c6
add _get_anchors
etpinard Dec 31, 2014
0497009
update _add_domain and _add_domain_is3D
etpinard Dec 31, 2014
a83ad48
code aesthetics
etpinard Dec 31, 2014
2d781f6
modify expected values in tests due to rounding errors
etpinard Dec 31, 2014
b8e9f53
add 2nd rowspan test (that discovered the bug)
etpinard Dec 31, 2014
46ed9d7
more test updating due to rounding errors
etpinard Dec 31, 2014
540b734
update shared axis tests
etpinard Dec 31, 2014
7b0e8fb
add 1 shared_xaxes=True, shared_yaxes=True test
etpinard Dec 31, 2014
f6a64d1
sub isEmpty -> is_empyt , is3D -> is_3d
etpinard Jan 2, 2015
bed60db
add info about 'insets' in docstring
etpinard Jan 4, 2015
50eeb8f
add try/except block for kwargs['insets']
etpinard Jan 4, 2015
1a2192e
aesthestic in SPEC_defaults
etpinard Jan 4, 2015
443217e
add functions checking and filling keys (for 'specs' & 'insets')
etpinard Jan 4, 2015
a72f043
send specs to _check_keys_and_fill()
etpinard Jan 4, 2015
8e3e83d
check and fill 'insets'
etpinard Jan 4, 2015
d30e7b9
raise Exception if non-valid kwarg is sent to get_subplots
etpinard Jan 4, 2015
f9235b3
loop through insets!
etpinard Jan 4, 2015
dfa47f7
add inset str reprensation
etpinard Jan 4, 2015
3ef8116
add wrong key & wrong type tests
etpinard Jan 4, 2015
ec25258
add 2 insets tests
etpinard Jan 4, 2015
25c8d85
update 'specs' docstring
etpinard Jan 4, 2015
330eeac
raise Exception if specs dims not equal to 'rows' and 'columns'
etpinard Jan 4, 2015
12cdffd
rm 'is_empty' from SPEC_defaults
etpinard Jan 4, 2015
e52ff4f
add cond for spec == None case in check_and_fill
etpinard Jan 4, 2015
bad84cd
pep8 tuple
etpinard Jan 4, 2015
0c83b9d
move spec is None cond at top of spec loop
etpinard Jan 4, 2015
45229d2
re-align specs loop
etpinard Jan 5, 2015
fa286a0
move right by one column:
etpinard Jan 5, 2015
f0c3997
add under/over-specified specs tests
etpinard Jan 5, 2015
feea0cc
update tests:
etpinard Jan 5, 2015
98b955f
add a colspan>1 + rowspan>1 in the same cell test
etpinard Jan 5, 2015
e5d753f
[need some feedback] add start_cell docstring
etpinard Jan 5, 2015
0d74fb3
add back the old get_subplots :
etpinard Jan 6, 2015
6df366e
mv get_subplots argument checks tests to the top of file
etpinard Jan 6, 2015
5bcbaaa
move make_subplots tests to test_make_subplots.py
etpinard Jan 6, 2015
2edb810
pep8 get_subplots docstring
etpinard Jan 6, 2015
421dd5f
improve make_subplots docstring
etpinard Jan 7, 2015
af67e90
replace 'columns' with 'cols'
etpinard Jan 7, 2015
7bb6ba2
rm '>>>' in docstring
etpinard Jan 7, 2015
67672dd
force 'specs' to be list of lists
etpinard Jan 7, 2015
a311719
force items in 'specs' to be either dicts or None
etpinard Jan 7, 2015
dd16fa2
define START_CELL and build grid using it
etpinard Jan 7, 2015
254cf13
sub 'grid_str' -> 'grid_ref':
etpinard Jan 7, 2015
46b6c73
fill in a layout obj, not a figure obj directly
etpinard Jan 7, 2015
4a6b718
remove i, j indices
etpinard Jan 7, 2015
1cb0026
improve and generalize algorithm:
etpinard Jan 7, 2015
964daff
rm grid_str code (taken care outside specs loop now)
etpinard Jan 7, 2015
7463f60
update (r, c) convention:
etpinard Jan 7, 2015
f0eea15
update _add_domain (accepts layout not fig)
etpinard Jan 7, 2015
95cded8
update insets loop:
etpinard Jan 7, 2015
7b0e5d1
improve 'grid_str' code
etpinard Jan 7, 2015
3f7572a
pep8 and add TODO
etpinard Jan 7, 2015
e9c2e01
test galore !!!
etpinard Jan 7, 2015
bfa69ce
add exception for out of range 'insets.cell'
etpinard Jan 7, 2015
0f75a2d
add tests for prev commit
etpinard Jan 7, 2015
9c34d84
sync for graph ref (trace 'scene')
etpinard Jan 7, 2015
d39a0be
make print_grid=True the default for make_subplots
etpinard Jan 9, 2015
87d645a
sub '!' -> ':' in print grid msg
etpinard Jan 9, 2015
08892a9
update shared_{x,y}axes docstring
etpinard Jan 9, 2015
e4d4936
capitalize ROW_DIR
etpinard Jan 9, 2015
2de9ad7
update get_anchors logic:
etpinard Jan 9, 2015
bd16672
add shared axes tests
etpinard Jan 9, 2015
6b2465b
paste grid_ref and grid_str to fig in make_subplots
etpinard Jan 9, 2015
0437513
add print_grid method to Figure
etpinard Jan 9, 2015
9a2767b
add append_trace method to Figure
etpinard Jan 9, 2015
f13a408
make _grid_ref and _grid_str attributes
etpinard Jan 9, 2015
857013c
fix typo in exception msg
etpinard Jan 9, 2015
7e2d3e0
better test name
etpinard Jan 9, 2015
ff0a112
add exception for row/col =< 0
etpinard Jan 9, 2015
8dc3f80
add tests for append_trace
etpinard Jan 9, 2015
87501d8
force set axis.position when anchor == 'free'
etpinard Jan 9, 2015
cebfae2
update tests
etpinard Jan 9, 2015
68aee36
update make_subplot docstring
etpinard Jan 9, 2015
4ee9b59
add docstring to append_trace and print_grid
etpinard Jan 9, 2015
d2d7a92
add Exception if rows / cols <= 0
etpinard Jan 10, 2015
1f1960d
add tests about last commit
etpinard Jan 10, 2015
e0301ad
add example in Figure.append_trace docstring on ref in make_subplots
etpinard Jan 10, 2015
3ac711f
v 1.5.0
etpinard Jan 10, 2015
5536194
Merge branch 'master' into revamp-get_subplots
etpinard Jan 10, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 61 additions & 14 deletions plotly/tools.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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.
Copy link
Contributor Author

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.

Copy link
Contributor

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?


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']
Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

tls.get_subplots(arragement=[[1],[2, 3], [4, 5, 3]])

Oops I just realized that the actually formula would have to be more complicated than what I wrote, but definitely doable.

Copy link
Contributor

Choose a reason for hiding this comment

The 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.

Copy link
Contributor

Choose a reason for hiding this comment

The 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
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per subplot horizontal and vertical spacing.

Copy link
Contributor

Choose a reason for hiding this comment

The 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,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

together with the indices in 'arragement', assigning shared could be easily done using list or list of lists of subplot indices.

Copy link
Contributor

Choose a reason for hiding this comment

The 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
Expand Down