5
$\begingroup$

I have the next differential equation

sol = ParametricNDSolve[{y'[t] == a y[t], y[0] == 1}, y, {t, 0, 10}, {a}]

And a Contour Plot of this equation

 ContourPlot[y[a][x] /. sol, {x, 0, 0.1}, {a, 0, 4},
   PlotLegends -> BarLegend[Automatic, 
    LegendMarkerSize -> 180,   LegendFunction -> "Frame", LegendMargins -> 5,   
    LegendLabel -> "y[a][x]"], Frame -> True,  FrameLabel -> {{"a", ""}, {"x", ""}}, 
     BaseStyle -> {FontWeight -> "Bold", FontSize -> 14}]

With this code, I obtain the next image

enter image description here

I would like to mark the line of constant value $1.5$. To mark this line I click on the line, but I would like to obtain something more "elegant" enter image description here

EDIT

There is a way of isolate that specific line? I mean getting something like this:

enter image description here

$\endgroup$
5
$\begingroup$
Clear["Global`*"]

sol = ParametricNDSolve[{y'[t] == a y[t], y[0] == 1}, y, {t, 0, 10}, {a}];

Show[
 ContourPlot[y[a][x] /. sol, {x, 0, 0.1}, {a, 0, 4},
  PlotLegends -> BarLegend[Automatic,
    LegendMarkerSize -> 180,
    LegendFunction -> "Frame",
    LegendMargins -> 5,
    LegendLabel -> "y[a][x]"],
  Frame -> True,
  FrameLabel -> {{"a", ""}, {"x", ""}},
  BaseStyle -> {FontWeight -> "Bold", FontSize -> 14}],
 ContourPlot[y[a][x] /. sol, {x, 0, 0.1}, {a, 0, 4},
  Contours -> {1.15},
  ContourStyle -> Directive[Thick, White],
  ContourShading -> None]]

enter image description here

Or

ContourPlot[y[a][x] /. sol, {x, 0, 0.1}, {a, 0, 4},
 PlotLegends -> BarLegend[Automatic,
   LegendMarkerSize -> 180,
   LegendFunction -> "Frame",
   LegendMargins -> 5,
   LegendLabel -> "y[a][x]"],
 Frame -> True,
 FrameLabel -> {{"a", ""}, {"x", ""}},
 BaseStyle -> {FontWeight -> "Bold", FontSize -> 14},
 Contours -> Range[1.05, 1.45, 0.05],
 ContourStyle -> ReplacePart[
   Array[Black, 9],
   3 -> Directive[Thick, Opacity[1, White]]]]

enter image description here

| improve this answer | |
$\endgroup$
  • $\begingroup$ I think that your answer, solve both of the problems, I mean the original question and the edit of the question, thank you. $\endgroup$ – No name May 18 at 17:57
3
$\begingroup$

How about:

  sol = ParametricNDSolve[{y'[t] == a y[t], y[0] == 1}, 
   y, {t, 0, 10}, {a}];
ContourPlot[y[a][x] /. sol, {x, 0, 0.1}, {a, 0, 4}, Frame -> True, 
 FrameLabel -> {{"a", ""}, {"x", ""}}, 
 BaseStyle -> {FontWeight -> "Bold", FontSize -> 14},
 Contours -> {1.15}, ContourStyle -> Directive[Thick, Red], 
 ContourShading -> None]

enter image description here

| improve this answer | |
$\endgroup$
2
$\begingroup$

Woudl this work?

ContourPlot[
  y[a][x] /. sol, {x, 0, 0.1}, {a, 0, 4},
  PlotLegends -> 
   BarLegend[Automatic, LegendMarkerSize -> 180, 
    LegendFunction -> "Frame", LegendMargins -> 5,
    LegendLabel -> "y[a][x]"],
  Frame -> True, FrameLabel -> {{"a", ""}, {"x", ""}},
  BaseStyle -> {FontWeight -> "Bold", FontSize -> 14},

  Contours -> {{1.15, Thick}}, ContourShading -> None
]

enter image description here

| improve this answer | |
$\endgroup$
2
$\begingroup$

1. You can use MeshFunctions + Mesh:

ContourPlot[y[a][x] /. sol, {x, 0, 0.1}, {a, 0, 4}, 
 MeshFunctions -> {y[a][x] /. sol /. {x -> #, a -> #2} &}, 
 Mesh -> {{{1.15, Directive[Opacity[1], Thick, White]}}}, 
 PlotLegends -> BarLegend[Automatic, LegendMarkerSize -> 180, 
   LegendFunction -> "Frame", LegendMargins -> 5, 
   LegendLabel -> "y[a][x]"], Frame -> True, 
 FrameLabel -> {{"a", ""}, {"x", ""}}, 
 BaseStyle -> {FontWeight -> "Bold", FontSize -> 14}]

enter image description here

Alternatively, you can use Mesh -> {{1.15}} and add the option MeshStyle -> Directive[White, Thick] to get the same picture.

A slightly more convenient approach is to use ParametricNDSolveValue instead of ParametricNDSolve:

pndsv = ParametricNDSolveValue[{y'[t] == a y[t], y[0] == 1}, y, {t, 0, 10}, {a}];

ContourPlot[pndsv[a][x], {x, 0, 0.1}, {a, 0, 4},  
 MeshFunctions -> {pndsv[#2][#] &}, 
 Mesh -> {{{1.15, Directive[Opacity[1], Thick, White]}}}, 
 PlotLegends -> BarLegend[Automatic, LegendMarkerSize -> 180, 
   LegendFunction -> "Frame", LegendMargins -> 5, 
   LegendLabel -> "y[a][x]"], Frame -> True, 
 FrameLabel -> {{"a", ""}, {"x", ""}}, 
 BaseStyle -> {FontWeight -> "Bold", FontSize -> 14}]

same picture

2. You can post-process ContourPlot output to change the directives for the desired contour line:

cp = ContourPlot[y[a][x] /. sol, {x, 0, 0.1}, {a, 0, 4}, 
   PlotLegends ->  BarLegend[Automatic, LegendMarkerSize -> 180, 
     LegendFunction -> "Frame", LegendMargins -> 5, 
     LegendLabel -> "y[a][x]"], Frame -> True, 
   FrameLabel -> {{"a", ""}, {"x", ""}}, 
   BaseStyle -> {FontWeight -> "Bold", FontSize -> 14}];

cp /.  t : Tooltip[_, 1.15] :> 
    (t /. {Opacity[_] -> Opacity[1], GrayLevel[0] -> Directive[Thick, White]})

enter image description here

| improve this answer | |
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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