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

Annotations improvements #4721

Merged
merged 11 commits into from
Apr 17, 2023
Merged

Annotations improvements #4721

merged 11 commits into from
Apr 17, 2023

Conversation

ivan-boikov
Copy link
Contributor

@ivan-boikov ivan-boikov commented Apr 11, 2023

Description

Figures
Generating code
using Plots
using Random

function test_2d(; N=8)
    Random.seed!(0)
    xy = ntuple(_ -> randn(N), 2); 
    pl0 = plot(xy...; marker=:circle, legend=:none, size=(2,2).*120); 
    annotate!(0.0, 0.0, text("0", 16, :red));
    annotate!((0.3, 0.3), text("REL", 12, :green, rotation=45));
    annotate!((5//6, 0.5), text("REL mixed", 12, :green, rotation=45));
    annotate!(xy..., @. text(string(1:N), :left));
    annotate!(:topcenter, "TOP");
    annotate!([:bottomcenter], ["BOT"]);
    annotate!([:topleft, :bottomright], ["TL", :BR])
end 

function test_3d(; N=8)
    Random.seed!(0)
    xyz = ntuple(_ -> randn(N), 3); 
    plot(xyz...; marker=:circle, legend=:none, size=(2,2).*120); 
    annotate!(0.0, 0.0, 0.0, text("0", :red));
    annotate!((0.3, 0.3, 0.3), text("REL", :green, rotation=45));
    annotate!((1, 0.5, 1//2), text("REL mixed", :green, rotation=45));
    annotate!(xyz..., @. text(string(1:N), :left))
end

gr()
savefig(test_2d(), "gr-2d.png")
savefig(test_3d(), "gr-3d.png")

pgfplotsx()
PGFPlotsX.latexengine!(PGFPlotsX.PDFLATEX)
savefig(test_2d(), "pgfx-2d.png")
savefig(test_3d(), "pgfx-3d.png")

inspectdr()
savefig(test_2d(), "idr-2d.png")
# no 3D

pythonplot()
savefig(test_2d(), "pyplot-2d.png")
savefig(test_3d(), "pyplot-3d.png")

plotlyjs()
savefig(test_2d(), "plotlyjs-2d.png")
savefig(test_3d(), "plotlyjs-3d.png")

In all cases master crashes, figures show PR

  • GR
    gr-2d gr-3d

  • PGFPlotsX
    pgfx-2d pgfx-3d

  • PythonPlot
    pyplot-2d pyplot-3d

  • InspectDR (2D only)
    idr-2d

  • Plotly
    plotlyjs-2d plotlyjs-3d

Attribution

@ivan-boikov ivan-boikov changed the title Annot Annotations improvements Apr 11, 2023
@ivan-boikov ivan-boikov marked this pull request as draft April 11, 2023 20:54
@BeastyBlacksmith
Copy link
Member

Interestingly, tests fail only on ubuntu, while on my linux machine they pass. Marked as draft.

Its the GraphRecipes tests that fail, not Plots.

@ivan-boikov
Copy link
Contributor Author

ivan-boikov commented Apr 12, 2023

I think I found the issue. If I understood correctly, in GraphPlots annotations are constructed in the form (x, y, label, fontsize) here https://github.com/JuliaPlots/GraphRecipes.jl/blob/d11908e87e425a7c4b9da2ffd7fd709097f9134e/src/graphs.jl#L1137 which I don't think follows the documentation https://docs.juliaplots.org/stable/api/#Plots.annotate!-Tuple, it should be (x, y, text(label, fontsize)). Moreover, a label passed can be a number too (that was the case in the failed test). So process_annotation can get something like (1.2, 3.4, 1, 10) and god knows if the 3rd number is a z or a label and PR's process_annotation got confused.
Maybe the best approach would be to internally convert annotations to named tuples or structs to prevent confusion once and for all. I am not sure I can do this cleanly without breaking changes (who knows, maybe there are other recipes doing the same thing), but I'll try.
Why windows and macos tests succeeded though? There are no GraphRecipes tests on those?

And could you also answer the question in the OP please? It's important for the PR.

@BeastyBlacksmith
Copy link
Member

BeastyBlacksmith commented Apr 13, 2023

it should be (x, y, text(label, fontsize))

Well, you can't do that in a recipe since text is part of Plots and not RecipesBase.

Why windows and macos tests succeeded though?

Yes, upstream tests are only run on ubuntu.

Before if lengths of annotation coordinates and annotation strings mismatched

Unfortunately we can't change that in a minor release, but one more reason more for explicit cycling, that I mentioned in #4565

dependabot bot and others added 5 commits April 15, 2023 14:35
Bumps [peter-evans/create-pull-request](https://github.com/peter-evans/create-pull-request) from 4 to 5.
- [Release notes](https://github.com/peter-evans/create-pull-request/releases)
- [Commits](peter-evans/create-pull-request@v4...v5)

---
updated-dependencies:
- dependency-name: peter-evans/create-pull-request
  dependency-type: direct:production
  update-type: version-update:semver-major
...

Signed-off-by: dependabot[bot] <[email protected]>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
* Add bounds check in expand_extrema

* Stupid mistake
@codecov
Copy link

codecov bot commented Apr 15, 2023

Codecov Report

Patch coverage: 64.51% and project coverage change: +0.31 🎉

Comparison is base (0e0f117) 90.00% compared to head (b8b7800) 90.31%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4721      +/-   ##
==========================================
+ Coverage   90.00%   90.31%   +0.31%     
==========================================
  Files          40       40              
  Lines        8360     8727     +367     
==========================================
+ Hits         7524     7882     +358     
- Misses        836      845       +9     
Impacted Files Coverage Δ
src/backends/pythonplot.jl 87.55% <0.00%> (+0.13%) ⬆️
src/backends/gr.jl 90.46% <50.00%> (+0.32%) ⬆️
src/components.jl 89.50% <66.66%> (-0.53%) ⬇️
src/args.jl 85.56% <100.00%> (+0.79%) ⬆️
src/backends/pgfplotsx.jl 88.18% <100.00%> (+0.43%) ⬆️

... and 28 files with indirect coverage changes

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

☔ View full report in Codecov by Sentry.
📢 Do you have feedback about the report comment? Let us know in this issue.

@ivan-boikov
Copy link
Contributor Author

ivan-boikov commented Apr 15, 2023

Thank you for answers, cycling indeed is important. I revised the processing, it has cycling and is still compact. Also tests are passed now, so marking as ready.

@ivan-boikov ivan-boikov marked this pull request as ready for review April 15, 2023 13:44
src/components.jl Outdated Show resolved Hide resolved
Copy link
Member

@t-bltg t-bltg left a comment

Choose a reason for hiding this comment

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

LGTM

@BeastyBlacksmith BeastyBlacksmith merged commit 1bd3561 into JuliaPlots:master Apr 17, 2023
@BeastyBlacksmith
Copy link
Member

Good job! Thank you 🙂

@ivan-boikov ivan-boikov deleted the annot branch April 20, 2023 19:03
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.

[FR] annotate! for 3D plots [BUG] Relative positioning of annotations tuple cannot mix integer and float
3 participants