4
$\begingroup$

I have a problem that requests that I plot two families of curves:

$$x^2+y^2=r^2\qquad\text{and}\qquad ax+by=0$$

I can get the first family with:

ContourPlot[x^2+y^2,{x,-3,3},{y,-3,3}]

Anyone have a good suggestion for superimposing the second family on the same plot?

$\endgroup$
1
  • $\begingroup$ Note that the second family of curves may be written y/x = -a/b. Then you can ContourPlot y/x. The numerics near the vertical lines gets finnicky, so you can equivalently plot ArcTan[y/x] or ArcTan[y,x] or anyFunctionOfOneVariable[y/x]. As far as making it look nice in terms of super-imposing, I think other solutions here are good. $\endgroup$ – evanb Mar 8 '16 at 6:29
6
$\begingroup$
s = Table[y - Tan@p x == 0, {p, 0, Pi, Pi/20}];
s1 = Table[y^2 + x^2 == r^2, {r, 0, 4, .3}]; 
ContourPlot[Evaluate@Join[s1, s], {x, -3, 3}, {y, -3, 3}]

Mathematica graphics

$\endgroup$
1
  • 2
    $\begingroup$ You should change the first line to s = Table[Cos@p y - Sin@p x == 0, {p, 0, Pi, Pi/20}]; this way you won't miss the x==0 line $\endgroup$ – BlacKow Mar 7 '16 at 17:27
3
$\begingroup$

Perhaps

ParametricPlot[r {Cos[t], Sin[t]}, {r, 0, 2}, {t, 0, 2 Pi},
 Mesh -> {9, 17}, PlotPoints -> 50]

Mathematica graphics

Or

ParametricPlot[r {Cos[t], Sin[t]}, {r, 0, 2 Sqrt[2]}, {t, 0, 2 Pi},
 Mesh -> {Round[9 Sqrt[2]], 17},
 RegionFunction -> Function[{x, y, u, v}, Abs[x] <= 2 && Abs[y] <= 2]]

or even just clip with PlotRange instead of RegionFunction. It produces a cleaner boundary. (Edit: Added some styling.)

ParametricPlot[r {Cos[t], Sin[t]}, {r, 0, 2 Sqrt[2]}, {t, 0, 2 Pi},
 Mesh -> {Round[9 Sqrt[2]], 31}, 
 MeshStyle -> (Directive[Thickness[0.005], Opacity[1], #] & /@ ColorData[97, "ColorList"]),
 BoundaryStyle -> (Directive[Thickness[0.005], Opacity[1], ColorData[97][2]]),
 PlotStyle -> None, Axes -> False, PlotRange -> 2]

Mathematica graphics

$\endgroup$
1
$\begingroup$

Closer to OP approach:

ContourPlot[{
  x^2 + y^2 == Range[10], 
  x Range[-10, 10] + y Join[Range[0, 10], Range[9, 0, -1]] == 0}, 
{x, -3, 3}, {y, -3, 3}]

Result:

enter image description here

With slight modification:

ContourPlot[{x^2 + y^2 == Range[1, 6, 0.5]^2, 
  x Range[-6, 6] + y Join[Range[0, 6], Range[5, 0, -1]] == 0}, 
{x, -3, 3}, {y, -3, 3}]

enter image description here

$\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.