Skip to content
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

Legend positioning for 3d plots in plotly #3840

Merged
merged 3 commits into from
Sep 23, 2021

Conversation

briederer
Copy link
Contributor

Disclaimer: This PR is more like a personal aesthetic thing with legends for 3D plots in Plotly.

Personally I got the feeling, that (especially) for 3D-plots with a square size (e.g. size=(400,400)), all the legends that are considered :inner are a bit too high. This is mainly due to the fact that a 3D plot has for most views a large empty space in the corners.

p1=scatter(rand(10,3),rand(10,3),rand(10,3),size=(400,400));
p2=scatter(rand(10,3),rand(10,3),rand(10,3),size=(400,400),legend=:top,title="test");

Before PR:
newplot(1)newplot(3)

With PR:
newplot(2)newplot(4)

Additionally this resolves the issue that a :top label overlaps with the title (although I would discourage :top labels at all).

Let me know what you think 😄

@codecov
Copy link

codecov bot commented Sep 23, 2021

Codecov Report

Merging #3840 (6e0b085) into master (6fa3dae) will decrease coverage by 0.01%.
The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3840      +/-   ##
==========================================
- Coverage   63.23%   63.22%   -0.02%     
==========================================
  Files          28       28              
  Lines        7489     7489              
==========================================
- Hits         4736     4735       -1     
- Misses       2753     2754       +1     
Impacted Files Coverage Δ
src/recipes.jl 59.49% <0.00%> (-0.11%) ⬇️
src/backends/gr.jl 89.34% <0.00%> (-0.09%) ⬇️
src/colorbars.jl 92.72% <0.00%> (+1.81%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update acca707...6e0b085. Read the comment docs.

@BeastyBlacksmith
Copy link
Member

wouldn't it would make sense to have it the same for 2D or are there issues? Once putting a 3D figure next to a 2D figure in plotly works it might be difficult to align the legends otherwise

@briederer
Copy link
Contributor Author

The alignment is indeed a valid point.

Didn't think about that. The problem with also shifting down in the 2D case is that it then takes up too much space of the plot.

My issue is that I really think that the 3D plots are wasting a lot of space by having such a huge separation between the data and the legend. For instance when I want to use a snapshot of 3D plots in a paper they don't look nicely because of the huge amount of whitespace.

I am completely up to rework this PR but in my opinion there should be a way too (manually?) pull the legend closer to the data in the 3d case.

@BeastyBlacksmith
Copy link
Member

BeastyBlacksmith commented Sep 23, 2021

Both GR and pgfplotsx allow passing a tuple of numbers where 0 is the beginning of the plot and 1 is the end of the plot to place the legend absolutely, maybe that would be an option here?
E.g. plot(1:5, legend = (0.5, 0.5))

@briederer
Copy link
Contributor Author

Indeed this does also work here.

Thanks for the help.

I changed the PR now such that only the hardcoded numbers in the code are not present anymore.

@BeastyBlacksmith BeastyBlacksmith merged commit 8d95333 into JuliaPlots:master Sep 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants