Re: Extracting contour values from ContourPlot
- To: mathgroup at smc.vnet.net
- Subject: [mg100873] Re: Extracting contour values from ContourPlot
- From: "Sjoerd C. de Vries" <sjoerd.c.devries at gmail.com>
- Date: Tue, 16 Jun 2009 21:55:21 -0400 (EDT)
- References: <h12gg4$ect$1@smc.vnet.net> <h13vp8$8pm$1@smc.vnet.net>
To build the legend it is necessary to determine the color Mathematica used in the areas between the contour lines. Something like this then draws the legend: cols = Cases[plt, RGBColor[___], Infinity]; labels = Cases[plt, _Tooltip, Infinity] /. Tooltip[_, lbl_] :> lbl; Graphics[ { Riffle[cols, Table[Rectangle[{0, i}, {1, i + 1}], {i, Length [cols]}]], Table[Text[labels[[-i]], {1.5, i + 1}], {i, Length[labels]}] } ] I wonder whether color and labels will always be sorted in this convenient order, though. Cheers -- Sjoerd On Jun 15, 1:06 am, Jens-Peer Kuska <ku... at informatik.uni-leipzig.de> wrote: > Hi, > > plt = ContourPlot[Cos[x*y], {x, -Pi, Pi}, {y, -Pi, Pi}]; > > and > > Cases[plt, _Tooltip, Infinity] /. Tooltip[_, lbl_] :> lbl > > ? > > Regards > Jens > > dg wrote: > > I have spent an hour researching this group and online, with no > > definitive answer. > > > The problem: I have an nxm matrix of z values that I want to plot with > > List(Contour|Density)Plot together with a legend that shows the > > *actual* values of the contours used in the plot. (Seems like a pretty > > basic thing to me....). I know how to draw a nice legend, that's not > > the problem. > > > I have found a way to do it: I can specify the contours and plot range > > explicitly. But what I really want is not to have to do this, and rely > > on the semi-intelligent mechanism of Mathematica to pick an appropriate= number > > of contours and their values, THEN use those to draw the legend. > > > It seems that there is no way to do this. That is, there is no way to > > extract the actual contour values used in the plot. I found a > > ColorBarPlot package which however does not work in Mathematica 7: > > <http://library.wolfram.com/infocenter/MathSource/7030/> > > > Is it really not possible to do > > this?