4
$\begingroup$

Let me give an example,

probe1 = ContourPlot[10 == x + y, {x, 0, 10}, {y, 0, 10}, Frame -> True, FrameLabel -> {"x", "y"}]

This plots 10=f[x,y]=x+y, for a set of point (x,y) that solved the equality. Moreover,

probe2 = ParametricPlot[{x y, x^2 + y^2}, {x, 0, 10}, {y, 0, 10}]

where g=g[x,y]=xy and h=h[x,y]=x^2+y^2, plots h=h[g[x,y]]. What I want is to plot only the case in which x+y=10. What should I do?

$\endgroup$
1
  • 2
    $\begingroup$ How about a parametric region Region[ParametricRegion[{{x y, x^2 + y^2}, x + y == 10}, {{x, 0, 10}, {y, 0, 10}}], Frame -> True] $\endgroup$ Commented Jul 5, 2019 at 21:02

2 Answers 2

4
$\begingroup$

Update: Adding multiple mesh lines and legends:

mesh = {{9, Directive[Red, Opacity[1], Thick]}, 
        {10, Directive[Green, Opacity[1], Thick]}, 
        {12, Directive[Black, Opacity[1], Thick]}};

ParametricPlot[{u t, u^2 + t^2}, {u, 0, 10}, {t, 0, 10}, 
  MeshFunctions -> {Function[{x, y, u, t}, u + t]}, 
  Mesh -> {mesh}, 
  PlotLegends -> LineLegend[## & @@ Reverse[Transpose[mesh]], LegendLabel -> "u + t"]]

enter image description here

Original answer:

You can use the argument of ContourPlot as the MeshFunctions option value in ParametricPlot as follows:

ParametricPlot[{u t, u^2 + t^2}, {u, 0, 10}, {t, 0, 10}, 
 MeshFunctions -> {Function[{x, y, u, t}, u + t - 10]}, 
 Mesh -> {{0}}, 
 MeshStyle -> Directive[Red, Thick]]

enter image description here

$\endgroup$
7
  • $\begingroup$ It worked. Thanks. Do you have a sugestion to include in the same ParametricPlot several cases of the condition, for example u+v-2 and u+v-5, etc? What should I change in your solution? $\endgroup$ Commented Jul 6, 2019 at 3:49
  • 1
    $\begingroup$ @PatrickElPollo, try ParametricPlot[{u t, u^2 + t^2}, {u, 0, 10}, {t, 0, 10}, MeshFunctions -> {Function[{x, y, u, t}, u + t]}, Mesh -> {{{9, Directive[Red, Opacity[1], Thick]}, {10, Directive[Green, Opacity[1], Thick]}, {12, Directive[Black, Opacity[1], Thick]}}}] $\endgroup$
    – kglr
    Commented Jul 6, 2019 at 4:03
  • $\begingroup$ thanks, again. Only one more detail, sorry... is it possible to label each Mesh to have a legend of them? $\endgroup$ Commented Jul 6, 2019 at 4:27
  • 1
    $\begingroup$ Patrick, please see the update. $\endgroup$
    – kglr
    Commented Jul 6, 2019 at 5:12
  • 1
    $\begingroup$ @PatrickElPollo, you can use PlotStyle -> White (but that also gets rid of the right boundary) $\endgroup$
    – kglr
    Commented Jul 14, 2019 at 23:56
1
$\begingroup$

This may be what you want

Clear["Global`*"]

eqn = 10 == x + y;

ysol[x_] = y /. Solve[eqn, y][[1]]

(* 10 - x *)

Show[
 ParametricPlot[
  {x y, x^2 + y^2},
  {x, 0, 10}, {y, 0, 10}],
 ParametricPlot[
  Evaluate[{x y, x^2 + y^2} /. y -> ysol[x]],
  {x, 0, 10},
  PlotStyle -> Red]]

enter image description here

$\endgroup$
2
  • $\begingroup$ it works, but what I want is a way to extract the pairs from ContourPlot when Solve does not work to use them as parameters in ParametricPlot. $\endgroup$ Commented Jul 5, 2019 at 19:39
  • $\begingroup$ @PatrickElPollo - have you tried using a numeric solver such as NSolve or FindRoot? $\endgroup$
    – Bob Hanlon
    Commented Jul 5, 2019 at 23:29

Your Answer

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

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