Fix the margins of subplots #622
Open
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.
In master the subplot margins are subtracted from the given subplot width/heights. Since top-left subplot should start in (0,1) and bottom-right should end at (1,0), the left margin is not subtracted from the leftmost subplots and the right margin -- from the rightmost. The same for heights. As the result the proportions of the plots drawn differ from the ones given to
subplot()
: in comparison to outer subplots the inner ones are more narrow than they should be. See e.g.:The PR changes how the
get_domains()
calculates the subplot positions. Instead of subtracting the margins from the subplot widths/heights, it rescales the width/heights so that the sum of margins and width/heights does not exceed 1.0 (the margins are not scaled since they are calculated wrt ticks/labels sizes). This approach preserves the relative subplot proportions. It looks like it also fixes thefree_y
case in #619.There are 2 open issues related to this PR:
get_domains()
there's no difference between left/right, only the left+right sum does matter. The same for top/bottom. So instead of expecting 4-elementmargins
vector,get_domains()
could be simplified to expect 2-elementspaces
vector.ggplotly()
) to avoid subplot overlaps. But certain combinations of client/server plot sizes result in overly large margins and reduced subplots. Would be nice if at least upon redraws the server can get the actual plot dimensions.