I have a very simple contour plot:
ContourPlot[ z Exp[-Sqrt[z^2 + x^2]/2.], {x, -10, 10}, {z, -10, 10},
ContourShading -> None, Contours -> 15,
ContourStyle -> {{Black, Thick}}]
I do not want the plot shaded, but I want to color the contour lines
according to a function of z (e.g., Sign[z], where z>0 is black, z<0
is red). Can this be done within ContourStyle?
I tried putting a function definition for the color inside
ContourShading, but I get an error since it's not a graphics directive
(and it's my understanding that ColorFunction is only for shading the
regions between contours).
Thanks for any input!
Porscha
Bob Hanlon
---- Porscha Louise McRobbie <pmcr...@umich.edu> wrote:
=============
Show[
Table[
ContourPlot[z Exp[-Sqrt[z^2 + x^2]/2.], {x, -10, 10}, {z, -10, 10},
ContourShading -> None, Contours -> {c},
ContourStyle -> {{Switch[Sign[c], 1, Black, -1, Red, 0, Blue],
Thick}}], {c, -1/2, 1/2, 1/10}]]
Cheers -- Sjoerd
On Nov 18, 1:58 pm, Porscha Louise McRobbie <pmcro...@umich.edu>
wrote:
My quick solution would be this:
cpl = ContourPlot[
z Exp[-Sqrt[z^2 + x^2]/2.], {x, -10, 10}, {z, -10, 10},
ContourShading -> None, Contours -> 15, ContourStyle -> {Thick}];
cpl /. {tt_Tooltip :> Sequence[If[tt[[2]] > 0, Black, Red], tt]}
which makes use of the fact that the tooltip contains the value of the
contourline
Have fun,
HK
My quick solution would be this:
cpl = ContourPlot[
z Exp[-Sqrt[z^2 + x^2]/2.], {x, -10, 10}, {z, -10, 10},
ContourShading -> None, Contours -> 15, ContourStyle -> {Thick}];
cpl /. {tt_Tooltip :> Sequence[If[tt[[2]] > 0, Black, Red], tt]}
which makes use of the fact that the tooltip contains the value of the
contourline
Have fun,
HK
Hi Again..
Just forgot to suggest a solution that involves RegionPlot. You'll
need to work a few more details, but in essence it is
f[z_, x_] = z Exp[-Sqrt[z^2 + x^2]/2.];
lf = #1 < f[x, y] < #2 & @@@
Table[{ii, ii + 0.05}, {ii, -0.6, 0.6, 0.2}]
RegionPlot[lf, {x, -10, 10}, {y, -10, 10},
ColorFunction -> Function[{x, y}, Hue[f[x, y] + 0.5]],
PerformanceGoal -> "Quality", PlotPoints -> 100]
Best
F
If you can express your equations in a ParametricPlot you can do what
you want.
Another way is to use StreamPlot, you'll have to define the vector
field of your function
f[z_, x_] = z Exp[-Sqrt[z^2 + x^2]/2.]
Then the vector field along which f[z,x] is constant
v[x_, y_] = {D[f[x, y], y], -D[f[x, y], x]}
and the stream plot with lines
StreamPlot[v[x, y], {x, -10, 10}, {y, -10, 10},
StreamColorFunction -> Function[{x, y, vx, vy, nxy}, Hue[f[x, y]]],
StreamStyle -> "Line"]
Many thanks for reminding me my undergrad calculus...
Best
F