Differentiate contour color based on different functions rather than the contour values - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-08-25T19:13:58Z https://mathematica.stackexchange.com/feeds/question/113081 http://www.creativecommons.org/licenses/by-sa/3.0/rdf https://mathematica.stackexchange.com/q/113081 1 Differentiate contour color based on different functions rather than the contour values DavidC https://mathematica.stackexchange.com/users/34958 2016-04-20T07:30:40Z 2016-04-20T08:02:02Z <p>I'm plotting contours by replacing different set of parameters into a ParametricNDSolve result. For instance I have three different sets of parameters {n,m,Ea,LogZ} that will be replaced into the contoursol function</p> <pre><code>contoursol[{n_?NumericQ, m_?NumericQ, Ea_?NumericQ, LogZ_?NumericQ}]:= Module[{t}, ParametricNDSolve[{T'[t] == htc[TA] (TA - T[t]), y'[t] == 10^LogZ Exp[-Ea/(R T[t])] y[t]^m (1 - y[t])^n, y == 10^-4, T == T0}, \[Alpha], {t, 0, 10}, {TA}]]; data1 = { 1.56407, 0.377154, 114957., 15.9797}; data2 = {1.43237, 0.334775, 110680., 15.141}; data3 = {1.31691, 0.450877, 101020., 13.5803}; </code></pre> <p>And when I use ContourPlot to generate the contours, I was having difficulties to differentiate the contours from different dataset of parameters. Since there's no PlotStyle but the ContourStyle, where all the contour colors were set based on the contour values rather than the function types. Below is my code:</p> <pre><code>ContourPlot[Evaluate[(1 - y[TE + 273.15][t]) /. {{contoursol[data1]},{contoursol[data2]}, {contoursol[data3]}}], {t, 0, 10}, {TE, 110, 180}, ContourStyle -&gt; {Grey, Green, Blue}, Contours -&gt; {5, 10, 30}, ContourLabels -&gt; Automatic, ImageSize -&gt; Large, ContourShading -&gt; False, PlotRange -&gt;All] </code></pre> <p>Can anyone please help me to figure how to make the contour colors based on the function type rather than the contour values? The only way I can think of is to use separate ContourPlot function and combine them using the Show function. Thank you in advance for your great help!</p> https://mathematica.stackexchange.com/questions/113081/-/113084#113084 2 Answer by Jason B. for Differentiate contour color based on different functions rather than the contour values Jason B. https://mathematica.stackexchange.com/users/9490 2016-04-20T08:02:02Z 2016-04-20T08:02:02Z <p>The syntax of <code>ContourPlot</code> doesn't seem to work that way, just giving it multiple functions in the input. Consider this, which is in essence what you are doing,</p> <pre><code>ContourPlot[{Sin[x] + Sin[y], Cos[x] + Cos[y]}, {x, -2 π, 2 Pi}, {y, -2 π, 2 Pi}, PlotPoints -&gt; 50, ContourStyle -&gt; {Red, Blue}, Contours -&gt; Range[-2, 2, .5], ContourShading -&gt; False, PlotRange -&gt; All] </code></pre> <p><a href="https://i.stack.imgur.com/wc9mf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wc9mf.png" alt="enter image description here"></a></p> <p>Here the <code>Contours -&gt;</code> rule has been ignored, and instead the red curve corresponds to the contour <code>Sin[x] + Sin[y] ==0</code> and the blue curve to <code>Cos[x] + Cos[y] ==0</code>.</p> <p>To get what you are after, you need to make two contour plots and combine them with <code>Show</code>. Here is a simple way to do it that uses <a href="https://reference.wolfram.com/language/tutorial/PureFunctions.html" rel="nofollow noreferrer">pure functions</a> and <a href="http://reference.wolfram.com/language/ref/Apply.html" rel="nofollow noreferrer"><code>Apply</code></a> to create the plot you are after,</p> <pre><code>Show[ ContourPlot[#1, {x, -2 π, 2 Pi}, {y, -2 π, 2 Pi}, PlotPoints -&gt; 50, ContourStyle -&gt; #2, Contours -&gt; Range[-2, 2, .5], ContourShading -&gt; False, PlotRange -&gt; All] &amp; @@@ {{Sin[x] + Sin[y], Red}, {Cos[x] + Cos[y], Blue}}] </code></pre> <p><a href="https://i.stack.imgur.com/cwZiQ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/cwZiQ.png" alt="enter image description here"></a></p>