MathGroup Archive 2002

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: LabelContourLines bug/feature

  • To: mathgroup at smc.vnet.net
  • Subject: [mg38459] RE: [mg38384] LabelContourLines bug/feature
  • From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
  • Date: Wed, 18 Dec 2002 01:53:40 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

>-----Original Message-----
>From: Martin Johansson [mailto:martin.n.johansson at emw.ericsson.se]
To: mathgroup at smc.vnet.net
>Sent: Friday, December 13, 2002 10:10 AM
>To: mathgroup at smc.vnet.net
>Subject: [mg38459] [mg38384] LabelContourLines bug/feature
>
>
>Hi!
>
>I'm using the function LabelContourLines from  Tom Wickham-Jones'
>ExtendGraphics package and I've been having some problems getting
>the proper labels on the contours. I have found a workaround,
>but it would still be interesting to see other possible solutions
>to the problem.
>
>Load the part of the package that we need:
>
>  << ExtendGraphics`LabelContour`
>
>Make a trivial contour plot: 
>
>  c1 = ContourPlot[x, {x, -2.5, 2.5}, {y, -2.5, 2.5}, 
>        Contours -> Range[-3, 3, 1], PlotRange -> All];
>
>This generates a contour plot with "vertical" lines
>at  x = {-2, -1, 0, 1, 2}, i.e., five lines.
>
>Put labels on the contours:
>
>  LabelContourLines[c1];
>
>This puts labels {-3, -2, -1, 0, 1} on the vertical lines
>described above, i.e., the labels start with the lowest value
>defined in the option statement "Contours -> Range[-3, 3, 1]"
>"Obviously", this is not what I wanted. It seems that
>LabelContourLines always uses the first value of Contours
>for the label of the contour line with the lowest value,
>and so on for increasing values, regardless of the range
>of values actually shown in the plot.
>
>My desired behavior would be to label each line according
>to its value. This quick fix (?) appears to produce what
>I want (edit in LabelContour.m):
>
>(* FindContours[ x_List, {z1_, z2_}] := x  Original version *)
>   
>   FindContours[ x_List, {z1_, z2_}] :=
>   Table[If[z1 <= x[[m]] <= z2, x[[m]] , {}],{m,Length[x]}]//Flatten
>
>It simply uses the full z-range of the contour plot
>to remove those contour values (as specified in Contours -> ...)
>that fall outside the range.
>
>Any comments on this? Is there a way to get the original code
>to put "proper" labels on corresponding contour lines?
>Is there a better (more efficient) way of fixing "the problem"?
>
>TIA,
>
>Martin
>

Martin,

David Park has given advice how to get satisfying results and you might like
to follow that. I just want to ask to your last question.

Obviously you spotted the origin of a bug in TWJ's package. To fix it, you
have several options:

(1) after loading the package issue the lines:

Begin["ExtendGraphics`LabelContour`Private`"]

FindContours[x_List, {z1_,z2_}] := Cases[x,
c_/;z1\[LessEqual]c\[LessEqual]z2]

End[]


(2) write these few lines (with an empty line at bottom) to a file called
Fixes.m and put that into the directory

\\<<your_path_to_WRI>>\ Wolfram
Research\Mathematica\<<version>>\AddOns\ExtraPackages\ExtendGraphics\


Then, when loading a package from ExtendGraphics, also load the fixes:

In[1]:= << ExtendGraphics`LabelContour`
In[2]:= << ExtendGraphics`Fixes`

The advantage of this solution is that you can play with different
modifications and test for while (and also add other fixes ad lib), without
sacrificing the original code.

(3) update the package.

BTW, I'm not quite sure whether the fix above is correct. I didn't test for
boundary cases, e.g. when a Contour comes very close to the effective
PlotRange. It might be usable, though.

--
Hartmut Wolf



  • Prev by Date: Re: saving a notebook into LaTeX
  • Next by Date: Re: Re: Re: Re: Why can't Mathematica find this root?
  • Previous by thread: RE: LabelContourLines bug/feature
  • Next by thread: Numeric Integration of Tabulated Integrand Function: Part I