Plots.jl icon indicating copy to clipboard operation
Plots.jl copied to clipboard

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

Open akriegman opened this issue 2 years ago • 2 comments

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?

akriegman avatar Apr 28 '22 16:04 akriegman

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.

BeastyBlacksmith avatar Apr 29 '22 07:04 BeastyBlacksmith

I went with the empty plot trick. Thanks!

akriegman avatar Apr 29 '22 14:04 akriegman