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

Overlay multiple contours on a single plot #3528

Closed
timholy opened this issue Jan 3, 2024 · 2 comments
Closed

Overlay multiple contours on a single plot #3528

timholy opened this issue Jan 3, 2024 · 2 comments
Labels
enhancement Feature requests and enhancements

Comments

@timholy
Copy link
Contributor

timholy commented Jan 3, 2024

Feature description

In some cases, it's useful to be able to overlay contour lines of two functions on the same plot. For example, if you're solving a system of equations

f(x, y) = 0
g(x, y) = 0

for points x, y, it can build insight to overlay contour lines for both f and g on the same plot.

I've tried this:

fig, ax, hc = contour(f; labels=true, labelcolor=:red)   # f is a matrix of grid-values of one function
contour!(ax, g; labels=true, labelcolor=:blue)           # g likewise

but the outcome is clearly wrong: among other things, I see the f contour lines re-labeled in blue.

A partial work-around is to overlay two surface plots on the same Axis3, but one has to manage transparency etc. more carefully than for a contour plot.

For plot types, please add an image of how it should look like

From Numerical Recipes:

image

@timholy timholy added the enhancement Feature requests and enhancements label Jan 3, 2024
@lazarusA
Copy link
Contributor

lazarusA commented Jan 3, 2024

could you show us some more code for your functions? please. The following works as in the reference image:

using GLMakie
f(x, y) = abs(sin(x)* sin(y))
g(x, y) = abs(cos(x)* cos(y))

x = y = -3:0.1:3
zf = [f(x, y) for x in x, y in y]
zg = [g(x, y) for x in x, y in y]

fig = Figure()
ax = Axis(fig[1,1])
contour!(ax, x, y, zf; labels=true, color=:black, linestyle=:dash, linewidth=2,
    labelcolor=:red, levels = [0.5,1])
contour!(ax, x, y, zg; labels=true, color=:dodgerblue, linewidth=2,
    labelcolor=:blue, levels = [0.5,1])  
fig
Screenshot 2024-01-03 at 21 10 07

@timholy
Copy link
Contributor Author

timholy commented Feb 5, 2024

Thanks! I don't have a record of my exact functions (they depended on a data set), but I'm guessing there must have been some degeneracy. I'll close this, with apologies for the noise.

@timholy timholy closed this as completed Feb 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Feature requests and enhancements
Projects
None yet
Development

No branches or pull requests

2 participants