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

Contour plot with all lines in one color #527

Closed
tomasaschan opened this issue Jan 6, 2015 · 7 comments · Fixed by #1469 · May be fixed by #1436
Closed

Contour plot with all lines in one color #527

tomasaschan opened this issue Jan 6, 2015 · 7 comments · Fixed by #1469 · May be fixed by #1436

Comments

@tomasaschan
Copy link
Contributor

I tried this:

xs = 1:10.
ys = 1:10.
zs = Float64[x^2*log(y) for x in xs, y in ys]
plot(x=xs, y=ys, z=zs, Geom.contour, Scale.discrete_color_manual("gray"))

but the only difference between with and without the Scale element is that with it, it seems that the colors are chosen as distinguishable, while without it they are from a spectrum corresponding to the function value.

Is there a way to get all the contour lines in a contour plot in the same color?

@tomasaschan
Copy link
Contributor Author

For reference, I realized this might be better suited for julia-users, and cross-posted it. If I get an answer there I'll be sure to post it here too.

@darwindarak
Copy link
Collaborator

This is probably not the best way to do this, but

plot(x=xs, y=ys, z=zs, Geom.contour, Scale.ContinuousColorScale(x->color("gray")))

seems to do what you want.

@dcjones dcjones closed this as completed in 621baf9 Jan 8, 2015
@dcjones
Copy link
Collaborator

dcjones commented Jan 8, 2015

Darwin's solution was pretty much to only way to do this, so I added a Scale.color_none which does what you want: suppress the default color scale.

@tomasaschan
Copy link
Contributor Author

Thanks, both @darwindarak and @dcjones for quick response. As it turns out, I'm using this in a layered plot where I have both a layer with contour levels (which I want all grey) and a few other layers with 2D trace plots, for which I have a defined, manual color key. Since Scale objects can't be applied to layers, I don't know how to apply the fixes you've provided to this use case.

Here's an example plot command of what I'm trying to do:

plot(
    layer(x=xwall, y=ywall, Geom.path, Theme(default_color=color("black"))),
    layer(x=trace1x, y=trace1y, color=["Trace 1" for _ in trace1x], Geom.path),
    layer(x=trace2x, y=trace2y, color=["Trace 2" for _ in trace2x], Geom.path),
    layer(x=xfield, y=yfield, z=zfield, Geom.contour, #= What to put here, to make contours gray? =#),
    Scale.discrete_color_manual("blue","green"),
    Guide.colorkey("Traces"),
    Guide.xticks(orientation=:horizontal)
)

I tried adding a color argument to the contour layer as well (with color=["psi" for x in xfield, y in yfield]) but it borked on me (``discretize_make_pda has no method matching discretize_make_pda(::Array{ASCIIString,2}, ::Array{ASCIIString,1})).

Is there any way to accomplish this?

@dcjones
Copy link
Collaborator

dcjones commented Jan 9, 2015

Oh, this is trickier than I thought. Maybe the most natural thing to do would be to add a color argument to Stat.contour and Geom.contour, so you could say Geom.contour(color="psi") and have all the contours colored by one factor.

@dcjones dcjones reopened this Jan 9, 2015
@tomasaschan
Copy link
Contributor Author

Couldn't Geom.contour just respect the default color of the theme? If I want to change the color of something plotted with e.g. Geom.path I'd add an argument Theme(default_color=color("gray")) to the layer or plot invocation, so I think it would be the most intuitive if that applied to contours as well.

@protogeezer
Copy link

Since this is still open, here's a tiny bit of code that will "manually" add contours to a plot (p). If a complete example is needed, let me know.

p = plot whatever goes under the contours.
c = contours(x_range,y_range,M,8);
for i = 1:length(c)
for j = 1:length(c[i].lines)
curr_x,curr_y = coordinates(c[i].lines[j])
l = layer(x=curr_x,y=curr_y,Geom.line(preserve_order=true),
Theme(default_color=RGB(.2,.2,.2),line_width=.4mm));
unshift!(p.layers,l[1]);
end
end
display(p)

contours

This was referenced May 3, 2020
@Mattriks Mattriks mentioned this issue Aug 1, 2020
3 tasks
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 a pull request may close this issue.

4 participants