-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
subplot titles respecting row_width and column_width #1245
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
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
c613ccc
first pass at subplot titles respecting row_width and column_width
Kully e83207a
add test for row_width and column_width in make_subplots
Kully b9ec250
fixes py2/3 compatibility (for tests)
Kully 13f491e
jon's comments
Kully 54d9065
remove print statement
Kully File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -13,6 +13,7 @@ | |
|
||
import six | ||
import copy | ||
import re | ||
|
||
from plotly import exceptions, optional_imports, session, utils | ||
from plotly.files import (CONFIG_FILE, CREDENTIALS_FILE, FILE_CONTENT, | ||
|
@@ -1001,7 +1002,6 @@ def _checks(item, defaults): | |
) for c in col_seq | ||
] for r in row_seq | ||
] | ||
|
||
# [grid_ref] Initialize the grid and insets' axis-reference lists | ||
grid_ref = [[None for c in range(cols)] for r in range(rows)] | ||
insets_ref = [None for inset in range(len(insets))] if insets else None | ||
|
@@ -1323,20 +1323,49 @@ def _pad(s, cell_len=cell_len): | |
subtitle_pos_x.append(sum(x_domains) / 2) | ||
for y_domains in y_dom: | ||
subtitle_pos_y.append(y_domains[1]) | ||
|
||
# If shared_axes is True the domin of each subplot is not returned so the | ||
# title position must be calculated for each subplot | ||
else: | ||
subtitle_pos_x = [None] * cols | ||
subtitle_pos_y = [None] * rows | ||
delt_x = (x_e - x_s) | ||
x_dom_vals = [k for k in layout.to_plotly_json().keys() if 'xaxis' in k] | ||
y_dom_vals = [k for k in layout.to_plotly_json().keys() if 'yaxis' in k] | ||
|
||
# sort xaxis and yaxis layout keys | ||
r = re.compile('\d+') | ||
|
||
def key_func(m): | ||
try: | ||
return int(r.search(m).group(0)) | ||
except AttributeError: | ||
return 0 | ||
|
||
xaxies_labels_sorted = sorted(x_dom_vals, key=key_func) | ||
yaxies_labels_sorted = sorted(y_dom_vals, key=key_func) | ||
|
||
x_dom = [layout[k]['domain'] for k in xaxies_labels_sorted] | ||
y_dom = [layout[k]['domain'] for k in yaxies_labels_sorted] | ||
|
||
for index in range(cols): | ||
subtitle_pos_x[index] = ((delt_x / 2) + | ||
((delt_x + horizontal_spacing) * index)) | ||
subtitle_pos_x *= rows | ||
for index in range(rows): | ||
subtitle_pos_y[index] = (1 - ((y_e + vertical_spacing) * index)) | ||
subtitle_pos_y *= cols | ||
subtitle_pos_y = sorted(subtitle_pos_y, reverse=True) | ||
subtitle_pos_x = [] | ||
for x_domains in x_dom: | ||
subtitle_pos_x.append(sum(x_domains) / 2) | ||
subtitle_pos_x *= rows | ||
|
||
if shared_yaxes: | ||
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. Do we have any tests that specify 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. no, i'll write one |
||
for index in range(rows): | ||
subtitle_pos_y = [] | ||
for y_domain in y_dom: | ||
subtitle_pos_y.append(y_domain[1]) | ||
subtitle_pos_y *= cols | ||
subtitle_pos_y = sorted(subtitle_pos_y, reverse=True) | ||
|
||
else: | ||
for index in range(rows): | ||
subtitle_pos_y = [] | ||
for y_domain in y_dom: | ||
subtitle_pos_y.append(y_domain[1]) | ||
subtitle_pos_y = sorted(subtitle_pos_y, reverse=True) | ||
subtitle_pos_y *= cols | ||
|
||
plot_titles = [] | ||
for index in range(len(subplot_titles)): | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Could you add an image of this expected figure to the PR?
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.
just a png in the file? I am not aware of image tests for this repo but I could be wrong
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.
No, I just meant in the GitHub PR so I could see what it looks like 🙂
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.