Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I have two questions concerning (List)ContourPlots. Since they are related to a single visualization desire, I have combined the questions into a single post. I'm hoping that they will be easy to answer.

The first question concerns coloring in (List)ContourPlots. Traditionally, in (List)ContourPlots, a specific color is assigned to a region inside of a contour based upon the magnitude of that region. In light of this, I would like to know: is there a way to apply a contour coloration scheme solely to the contours themselves and not to the regions that they enclose? More specifically, I am wanting to ensure that the regions inside the contours will be transparent, like in ContourPlot[Sin[x] Sin[y], {x, -3, 3}, {y, -3, 3}, ContourShading -> None], when I go to save out the ListContourPlots as a PDF/EPS figure. However, since the interior regions of the contours are no longer colored, I'd like to transfer the color that would have been used for that region to the associated contour that encloses it. If possible, I'd also like to have a white border surrounding the individual contours. My ultimate desire is to overlay the contour plot on top of another image and it can sometimes be difficult to distinguish the colors from the plot from those of the image; consequently, I'm hoping that a white border around each colored contour will help with that.

In a related post, I asked about how to apply a perspective transformation to two-dimensional (List)StreamPlots such that it would give the illusion of depth. Since I am still very much a beginner when it comes to Mathematica, I was wondering: is there was a simple way to apply the same idea to (List)ContourPlots? More specifically, I have a ListStreamPlot that is oriented in the exact manner that I need:

data = {{{1, 1}, {1.0, 0.0}}, {{11, 1}, {0.971194, 0.0}}, {{21, 1}, {0.963011, 0.0}}, {{31, 1}, {0.993688, 0.0}}, {{41, 1}, {1.023889, 0.0}}, {{51, 1}, {1.024193, 0.0}}, {{61, 1}, {1.010802, 0.0}}, {{71, 1}, {1.032089, 0.0}}, {{81, 1}, {1.026697, 0.0}}, {{91, 1}, {0.987981, 0.0}}, {{101, 1}, {1.025693, 0.0}}, {{111, 1}, {1.105825, 0.0}}, {{121, 1}, {1.098795, 0.0}}, {{131, 1}, {1.065537, 0.0}}, {{141, 1}, {1.012451, 0.0}}, {{151, 1}, {1.0, 0.0}}, {{1, 11}, {1.0, -0.083697}}, {{11, 11}, {0.932164, -0.106793}}, {{21, 11}, {0.925340, -0.192984}}, {{31, 11}, {1.122307, -0.187170}}, {{41, 11}, {1.161864, 0.085156}}, {{51, 11}, {0.976324, 0.115229}}, {{61, 11}, {0.978851, 0.035055}}, {{71, 11}, {1.049432, -0.030869}}, {{81, 11}, {0.936428, 0.062604}}, {{91, 11}, {0.912342, -0.146168}}, {{101, 11}, {1.147333, -0.143745}}, {{111, 11}, {1.166712, 0.127165}}, {{121, 11}, {1.041843, 0.129961}}, {{131, 11}, {1.045287, 0.083479}}, {{141, 11}, {0.994206, 0.122328}}, {{151, 11}, {1.0, 0.132739}}, {{1, 21}, {1.0, -0.023829}}, {{11, 21}, {0.890156, -0.030084}}, {{21, 21}, {0.674394, -0.050241}}, {{31, 21}, {0.0, 0.0}}, {{41, 21}, {0.658960, -0.210046}}, {{51, 21}, {0.716182, 0.091213}}, {{61, 21}, {0.472093, -0.225292}}, {{71, 21}, {0.732020, 0.265153}}, {{81, 21}, {0.843532, 0.369957}}, {{91, 21}, {0.279971, -0.348445}}, {{101, 21}, {0.963035, -0.753370}}, {{111, 21}, {1.002857, 0.538380}}, {{121, 21}, {0.756004, 0.204065}}, {{131, 21}, {0.806599, -0.138649}}, {{141, 21}, {0.913204,  0.279003}}, {{151, 21}, {1.0, 0.159432}}, {{1, 31}, {1.0, 0.044899}}, {{11, 31}, {0.908289, 0.060171}}, {{21, 31}, {0.856098, 0.122421}}, {{31, 31}, {0.762294, 0.042601}}, {{41, 31}, {0.0, 0.0}}, {{51, 31}, {-0.438033, 0.780580}}, {{61, 31}, {0.382021, -0.726038}}, {{71, 31}, {0.550500, -0.113628}}, {{81, 31}, {0.860478, 0.363810}}, {{91, 31}, {1.373814, -0.269792}}, {{101, 31}, {0.153576, -0.482892}}, {{111, 31}, {0.113453, 0.274464}}, {{121, 31}, {0.286391, 0.307524}}, {{131, 31}, {0.275092, -0.174137}}, {{141, 31}, {0.651551, -0.053446}}, {{151, 31}, {1.0, 0.028982}}, {{1, 41}, {1.0, 0.091944}}, {{11, 41}, {0.942248, 0.107845}}, {{21, 41}, {0.914909, 0.147823}}, {{31, 41}, {0.914062, 0.226842}}, {{41, 41}, {1.090780, 0.280458}}, {{51, 41}, {1.423264, 0.011814}}, {{61, 41}, {1.084930, -0.364051}}, {{71, 41}, {0.899861, -0.177124}}, {{81, 41}, {0.992899, -0.106340}}, {{91, 41}, {1.136605, -0.039446}}, {{101, 41}, {0.830366, 0.086879}}, {{111, 41}, {0.653521, 0.119604}}, {{121, 41}, {0.862727, 0.513709}}, {{131, 41}, {1.041204, -0.599559}}, {{141, 41}, {0.911816, -0.171321}}, {{151, 41}, {1.0, -0.089802}}, {{1, 51}, {1.0, 0.0}}, {{11, 51}, {0.972851, 0.0}}, {{21, 51}, {0.958161, 0.0}}, {{31, 51}, {0.956957, 0.0}}, {{41, 51}, {1.008198, 0.0}}, {{51, 51}, {1.082196, 0.0}}, {{61, 51}, {1.119506, 0.0}}, {{71, 51}, {1.011644, 0.0}}, {{81, 51}, {0.905500, 0.0}}, {{91, 51}, {0.811638, 0.0}}, {{101, 51}, {0.953396, 0.0}}, {{111, 51}, {0.978083, 0.0}}, {{121, 51}, {1.166181, 0.0}}, {{131, 51}, {1.289609, 0.0}}, {{141, 51}, {1.066669, 0.0}}, {{151, 51}, {1.0, 0.0}}};

ypos = 25;
data3d1 = ListStreamPlot[data, StreamPoints -> Fine, StreamScale -> Tiny, StreamStyle -> Thick, StreamColorFunction -> ColorData[{"CandyColors", "Reverse"}]][[1]] /. Arrow[pts_] :> Arrow[{#[[1]], ypos, #[[2]]} & /@ pts];
Graphics3D[Rotate[Rotate[Rotate[{data3d1}, 0 Degree, {1, 0, 0}], 0 Degree, {0, 1, 0}], 15 Degree, {0, 0, 1}], ViewPoint -> .009 {90, -7, 3}, Axes -> False, Boxed -> False]

I would like to ensure that the corresponding ListContourPlot is also oriented in the same way and has the same color scheme applied only to the contours (and not the regions inside the contours) so that I can manually layer it on my background image in LaTeX (tikz/pgf).

As an aside, if someone knows how to apply a white border around each of the ListStreamPlot arrows, I'd greatly appreciate a solution for that too!

share|improve this question
    
it seems your aside can be done by doing the arrows twice with different thickness: once white and then pink? –  chris May 11 at 9:26
1  
You should not combine multiple questions into one just because you need answers to all of them to get the final result you're after. The site works better if you ask one question at a time. Suppose different people provide answers to the different questions - which one will you accept? Or should people only post if they can answer all the questions? What if one of the questions is a duplicate or off topic - shall we close the whole thing? –  Simon Woods May 11 at 11:51
1  
You should also consider future visitors to the site. What if someone is searching for how to put a border around streamplot arrows - they probably won't expect to find the answer under a question about "Contour coloring"! –  Simon Woods May 11 at 11:51
    
I appreciate the advice. I will be sure to act on it if and when I go to post any future questions for the Mathematica StackExchange community. Moreover, if you believe it prudent, I will go ahead and fragment my above questions into three separate ones. –  isledge May 11 at 22:46

2 Answers 2

up vote 4 down vote accepted
cp = ContourPlot[Sin[x] Sin[y], {x, -3, 3}, {y, -3, 3},  ContourShading -> None, 
    ContourStyle -> Thread[{Thick, ColorData[1, "ColorList"]}],
    Background -> Black, ImageSize -> 400];
cp2 = cp /.{drctv___, a: _Line ..} :>{ drctv, White, Thickness[.015], a, drctv,Thick, a};
Row[{cp, cp2}, Spacer[5]]

enter image description here

For ListStreamPlot the Arrowheads need to be treated separately in post-processing the Arrows to put a white edge on the whole glyph. Using an alternative glyph for stream styles (e.g., any of the available glyphs that produce a Polygon) it gets easier to post-process. For example:

lsp = ListStreamPlot[data, StreamPoints -> Fine, 
       StreamScale -> {Small, Automatic, .02}, StreamStyle -> "PinDart", 
       StreamColorFunction -> 1, ImageSize -> 400]

enter image description here

g3D = Graphics3D[Rotate[#, 15 Degree, {0, 0, 1}], Background -> Black,
       Boxed -> False, ImageSize -> 600, BoxRatios -> {3, 3, 2}, 
       ViewPoint -> .009 {90, -7, 3}, Axes -> False] &;
lsp[[1]]/. Polygon[p_] :> {EdgeForm[White], Polygon[{#[[1]],ypos,#[[2]]}&/@ p]}//g3D

enter image description here

Update: Using the same perspective transformation on the cp2:

 cp2[[1]] /. GraphicsComplex[p_, q__] :> 
         GraphicsComplex[{#[[1]], ypos, #[[2]]} & /@ p, q] // g3D

enter image description here

share|improve this answer
    
I really appreciate this, kguler! Out of curiosity, is there an easy way to apply the same perspective transformation from the ListStreamPlot to the ContourPlot cp2? –  isledge May 13 at 22:15
    
@isledge, just posted an update on how to apply g3D to cp2. –  kguler May 13 at 22:33

This is probably only a partial answer but.. it deals with the white background issue:

u = ImageResize[Import["ExampleData/lena.tif"], 400];

Now a possible stream line

pl = StreamPlot[{-1 - (x/100)^2 + (y/100), 
    1 + (x/100) - (y/100)^2}, {x, 0, 400}, {y, 0, 400}, 
   StreamPoints -> Fine, StreamScale -> Small, StreamStyle -> Thick, 
   StreamColorFunction -> ColorData[{"Heat", "Reverse"}],
   ImageSize -> 400];

and the same with a white background; (it's not very efficient to redo the plot !)

pl0 = StreamPlot[{-1 - (x/100)^2 + (y/100), 
    1 + (x/100) - (y/100)^2}, {x, 0, 400}, {y, 0, 400}, 
   StreamPoints -> Fine, StreamScale -> Small, 
   StreamStyle -> Directive[White, AbsoluteThickness[4]],
   ImageSize -> 400];

Show[ImageResize[u, 400], pl0, pl]

Mathematica graphics

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.