RE: combining two contour plots

*To*: mathgroup at smc.vnet.net*Subject*: [mg47353] RE: [mg47320] combining two contour plots*From*: "David Park" <djmp at earthlink.net>*Date*: Tue, 6 Apr 2004 06:36:43 -0400 (EDT)*Sender*: owner-wri-mathgroup at wolfram.com

Vassilis, I always thought it would be nice if one of the standard colors was "Transparent". Overlaying countour plots is a slightly dubious operation. You could do something like the following, but it has problems. Needs["Graphics`Colors`"] graphics1 = First[Graphics[plot1]] /. {White, __} -> {}; graphics2 = First[Graphics[plot2]] /. {White, __} -> {}; Show[Graphics[{graphics1, graphics2}], AspectRatio -> Automatic, Frame -> True]; or Show[Graphics[{First[Graphics[plot2]], graphics1}], AspectRatio -> Automatic, Frame -> True]; But then we see that the polygons from ContourPlot converted to Graphics are not the true regions, but advantage is taken of overlaying. You could show the second set of contours with just lines. graphics2lines = Cases[First[Graphics[plot2]], Line[_], \[Infinity]]; Show[Graphics[{First[Graphics[plot1]], graphics2lines}], AspectRatio -> Automatic, Frame -> True]; But I can solve the problem with the DrawGraphics package from my web site. Needs["DrawGraphics`DrawingMaster`"] The following makes a 25 x 25 grid of squares that fill your region. polygrid = MakePolyGrid[{25, 25}, {{-3, -3}, {3, 3}}] // N; The following trims and SELECTS OUT the polygons that fall within the two contour regions for your second plot. polys1 = TrimPolygons[#1^2 - #2^2 & , {0.5, 1}][polygrid]; polys2 = TrimPolygons[#1^2 - #2^2 & , {1, 3}][polygrid]; This then combines the second contour regions on top of the first contour plot. Since only the polygons within the contour regions are rendered there is no White region to cover up the first plot. Of course, all the contour regions could have been made with TrimPolygons. Show[Graphics[{First[Graphics[plot1]], Green, polys1, HotPink, polys2, Black, graphics2lines}], AspectRatio -> Automatic, Frame -> True]; David Park djmp at earthlink.net http://home.earthlink.net/~djmp/ From: Vassilis Spanos [mailto:spanos at physics.umn.edu] To: mathgroup at smc.vnet.net Hi, I read the archives, but unfortunately I didn't find an answer to a problem I face. I want to combine to colored regions made with ContourPlot function, and using Show one covers totally another, presumably because white is really white color and not transparent. Thanks a lot, Vassilis Spanos Here is what I am doing ... colfun[contourvals_, colorlist_][z_] := Module[{i}, If[z > Last[contourvals], Return[Last[colorlist]]]; i = 1; While[z > contourvals[[i]], i++]; colorlist[[i]]] contourvals = {1., 2., 4.}; colorlist = {White, RoyalBlue, Yellow, White}; plot1 = ContourPlot[x^2 + y^2, {x, -3., 3}, {y, -3., 3.}, Contours -> contourvals, ColorFunction -> colfun[contourvals, colorlist], ColorFunctionScaling -> False, ContourShading -> True, PlotPoints -> 25]; contourvals = {0.5, 1., 3.}; colorlist = {White, Green, HotPink, White}; plot2 = ContourPlot[x^2 - y^2, {x, -3., 3}, {y, -3., 3.}, Contours -> contourvals, ColorFunction -> colfun[contourvals, colorlist], ColorFunctionScaling -> False, ContourShading -> True, PlotPoints -> 25]; Show[plot2, plot1]