1
$\begingroup$

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

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[0] == 10^-4, T[0] == 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};

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:

ContourPlot[Evaluate[(1 - y[TE + 273.15][t]) /. {{contoursol[data1]},{contoursol[data2]}, {contoursol[data3]}}], {t, 0, 10}, {TE, 110, 180}, ContourStyle -> {Grey, Green, Blue}, Contours -> {5, 10, 30}, ContourLabels -> Automatic, ImageSize -> Large, ContourShading -> False, PlotRange ->All]

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!

$\endgroup$
2
  • $\begingroup$ I have trouble using your code: In the ParametricNDSolve you have $\alpha$ where I think you want to have {y,T}, and also you don't have definitions for {T0, R, htc}. But the gist of the question is that you are doing a contourplot of 2 different functions overlaid together and you want a way to distinguish the contour lines from one function or the other? $\endgroup$
    – Jason B.
    Apr 20, 2016 at 7:48
  • $\begingroup$ Exactly! The objective is to distinguish the contour lines from one function to the other. I'm sorry for the typo and the missing information. There were originally many other unimportant information I didn't post since I was thinking not to distract the main issue. Thank you @JasonB for pointing this out :) $\endgroup$
    – DavidC
    Apr 20, 2016 at 7:53

1 Answer 1

3
$\begingroup$

The syntax of ContourPlot 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,

ContourPlot[{Sin[x] + Sin[y], Cos[x] + Cos[y]},
 {x, -2 π, 2 Pi}, {y, -2 π, 2 Pi},
 PlotPoints -> 50,
 ContourStyle -> {Red, Blue},
 Contours -> Range[-2, 2, .5],
 ContourShading -> False,
 PlotRange -> All]

enter image description here

Here the Contours -> rule has been ignored, and instead the red curve corresponds to the contour Sin[x] + Sin[y] ==0 and the blue curve to Cos[x] + Cos[y] ==0.

To get what you are after, you need to make two contour plots and combine them with Show. Here is a simple way to do it that uses pure functions and Apply to create the plot you are after,

Show[
 ContourPlot[#1, {x, -2 π, 2 Pi}, {y, -2 π, 2 Pi},
    PlotPoints -> 50,
    ContourStyle -> #2,
    Contours -> Range[-2, 2, .5],
    ContourShading -> False,
    PlotRange -> All] & @@@
  {{Sin[x] + Sin[y], 
    Red}, {Cos[x] + Cos[y], Blue}}]

enter image description here

$\endgroup$
1
  • $\begingroup$ This is fantastic! @JasonB I really appreciate your instant and informative reply! Thank you so much! $\endgroup$
    – DavidC
    Apr 20, 2016 at 8:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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