JuliaPlots / Plots.jl

Powerful convenience for Julia visualizations and data analysis
https://docs.juliaplots.org
Other
1.84k stars 354 forks source link

[FR] How to include a contour plot in the legend? #4187

Open akriegman opened 2 years ago

akriegman commented 2 years ago

I am using a contour plot with a single level to plot an equipotential. I'd like to have a legend entry for this curve instead of the colorbar, since the colorbar isn't very useful when there's only one level. I managed to hide the color bar, but I was unable to get a legend entry to appear. MWE:

contour(
  -1:0.1:1, -1:0.1:1, (x, y) -> sin(x*y),
  levels = [0.2],
  colorbar = false,
  label = "line", # does nothing
)

Any ideas? Can this feature be added?

BeastyBlacksmith commented 2 years ago

Thats currently disabled. See here: https://github.com/JuliaPlots/Plots.jl/blob/54a6518d59498fb24b5c25a90cd91ceadb7e26de/src/subplots.jl#L42-L61

You could check out, what the side-effects are of enabling it and play with it in a PR.

As a workaround you could add an empty plot with a legend entry.

akriegman commented 2 years ago

I went with the empty plot trick. Thanks!

jonniediegelman commented 1 month ago

Can we open this back up? I'd really like to have this feature and the empty plot trick doesn't play well with plot recipes.