Re: Points on a ContourPlot
- To: mathgroup at smc.vnet.net
- Subject: [mg91752] Re: Points on a ContourPlot
- From: "David Park" <djmpark at comcast.net>
- Date: Sun, 7 Sep 2008 05:36:04 -0400 (EDT)
- References: <g9t6o4$j9v$1@smc.vnet.net>
I love this level jumping! But then, what else can you do?
You didn't provide the actual function to be plotted, so here I make up my
own:
StabilityFnlens[x_, y_] := x^2 + 2 x y + Sin[x y/5];
You almost got it but you had an extra Graphic expression. (I changed the
PlotRange to accomodate my function. You probably don't need 100 PlotPoints.
Try using MaxRecursion first. I also picked some colors that are more
pleasant than the default coloring.)
Show[
ContourPlot[
StabilityFnlens[f1, f2], {f1, -10, 30}, {f2, -10,
30},(*ContourStyle->None,*)ContourLabels -> Automatic,
ColorFunction -> ColorData["IslandColors"],
PlotPoints -> 25, Contours -> 10, PlotRange -> Automatic,
Frame -> True, FrameStyle -> Directive[Thick],
LabelStyle -> {18, FontFamily -> "Arial"}],
Graphics[{Red, PointSize[Large],
Point[{{5, 5}, {9, 9}, {10, 10}, {20, 20}}]}]
]
There is another method to add the extra points and that is to use the
Epilog option.
ContourPlot[
StabilityFnlens[f1, f2], {f1, -10, 30}, {f2, -10,
30},(*ContourStyle->None,*)ContourLabels -> Automatic,
PlotPoints -> 25,
Contours -> 10,
ColorFunction -> ColorData["IslandColors"],
PlotRange -> Automatic,
Epilog -> {Red, PointSize[Large],
Point[{{5, 5}, {9, 9}, {10, 10}, {20, 20}}]},
Frame -> True,
FrameStyle -> Directive[Thick],
LabelStyle -> {18, FontFamily -> "Arial"}]
Many users find these constructions difficult because level switching is
tedious and the use of Epilog is not immediately obvious. And suppose that
you wanted to draw another special curve on top of the contour plot? Here is
an example where I generate a set of random points and then fit a linear
function through the points.
pts = Table[{x,
x + RandomReal[{-2, 2}]}, {x, {2, 5, 7, 9, 15, 20, 22, 28}}];
FindFit[pts, a x + b, {a, b}, x];
f[x_] = a x + b /. %;
With the Presentations package it is very easy to draw all these items
together. We just draw one item after another. No level jumping, no Show, no
Epilog, no wondering which options are picked up in which order.
Needs["Presentations`Master`"]
Draw2D[
{(* Make contour plot *)
ContourDraw[StabilityFnlens[f1, f2], {f1, -10, 30}, {f2, -10, 30},
ContourLabels -> Automatic, PlotPoints -> 25,
Contours -> 10,
ColorFunction -> ColorData["IslandColors"],
PlotRange -> Automatic],
(* Draw the linear fit to the points *)
Draw[f[x], {x, -10, 30}],
(* Add red points *)
Red, PointSize[Large], Point[pts]},
Frame -> True,
FrameStyle -> Directive[Thick],
LabelStyle -> {18, FontFamily -> "Arial"}]
How much time would that save you?
--
David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/
"SeekUp" <seek.up.girl at gmail.com> wrote in message
news:g9t6o4$j9v$1 at smc.vnet.net...
>I am trying to add Points to my ContourPlot to highlight certain points.
>The
> code below doesn't work. Any clues how to do it?
>
> tia
>
> --------------------------------------------------------------------------
>
> Show[
>
>
> Graphics[ContourPlot[StabilityFnlens[f1, f2], {f1, -10, 30}, {f2, -10,
> 30},(*ContourStyle->None,*)ContourLabels -> Automatic, PlotPoints -> 100,
> Contours -> 5, PlotRange -> {-1, 1},Frame -> True,FrameStyle ->
> Directive[Thick],LabelStyle -> {18, FontFamily -> "Arial"}],
>
> Graphics[{Red, PointSize[Large], Point[{{5, 5}, {9, 9}, {10, 10}, {20,
> 20}, }]}] (* doesn't work *)
> ]
> ]
>
>
>