RE: LabelContourLines bug/feature
- To: mathgroup at smc.vnet.net
- Subject: [mg38419] RE: [mg38384] LabelContourLines bug/feature
- From: "David Park" <djmp at earthlink.net>
- Date: Sat, 14 Dec 2002 03:20:07 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
Martin, You can label contour plots, and in fact any plot lines that have a constant function on them, using the DrawLineLabels routine in the DrawGraphics package at my web site below. There are examples shown in the DrawGraphics Help. Here is your example. Needs["DrawGraphics`DrawingMaster`"] Draw2D[ {g = ContourDraw[x, {x, -2.5, 2.5}, {y, -2.5, 2.5}, Contours -> Range[-3, 3, 1]], g // DrawLineLabels[#1 &, 0.6 &, DrawLLFormat -> (Round), DrawLLTextOptions -> {Background -> White}]}, Frame -> True, AspectRatio -> Automatic]; I will send you a gif image of the resulting plot separately so you can see that it works. David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Martin Johansson [mailto:martin.n.johansson at emw.ericsson.se] To: mathgroup at smc.vnet.net 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