I can't figure how to draw a line with PolarPlot.

A vertical line through a is $r \cos(\theta) = a$, so

PolarPlot[a/Cos[theta], {theta, -Pi, Pi}]


A horizontal line through b is $r \sin(\theta)=b$, so

PolarPlot[b/Sin[theta], {theta, -6, 6}] 

works. (Using {theta, -Pi, Pi} doesn't work because of dividing by $\sin(0)=0$ I guess.)

How do I draw a radial line with $\theta = \pi/3$? Should be a line with slope $\tan(\pi/3)$. Can it be done with PolarPlot? I guess not since you have to give a function of $r$.

  • 4
    $\begingroup$ Related question: "how do I draw the line $x=1$ using only Plot[]?" $\endgroup$ – J. M.'s torpor Apr 29 '13 at 3:59
  • $\begingroup$ You can't draw this exactly but you can define a tangent arc of arbitrarily large radius which passes through the origin at the angle you want. Try creating a circle with variable radius which you can get to cut through (0,0) and then increase the radius until it looks like you want it to. $\endgroup$ – Jonathan Shock Apr 29 '13 at 5:11
  • 3
    $\begingroup$ Can't you just use Epilog for this goal? $\endgroup$ – Sjoerd C. de Vries Apr 29 '13 at 5:45
  • $\begingroup$ Mathematica is madness. On paper I write theta = pi/4 (or whatever angle) to get an expression of a line in polar coordinates. But Mathematica needs 140 characters of code??? $\endgroup$ – Brute Force Mickey Mouse Jan 19 '18 at 3:52
  • $\begingroup$ Just add the Epilog->{Line@{{x0,y0},{x1,y1}} at the end of PolarPlot options list $\endgroup$ – Rom38 Jan 19 '18 at 4:52

My friend, what you ask for is madness. Assuming you're completely aware of just doing this, or similar:

 PolarPlot[{4/Cos[theta], 4/Sin[theta]}, {theta, -6, 6}],
 Graphics[Rotate[Line[500 {{-1, 0}, {1, 0}}], Pi/3]]]

enter image description here

Here's the most obvious brute-force mickey mouse approach:

PolarPlot[{4/Cos[theta], 4/Sin[theta], Evaluate[
   If[Pi/3 < theta < Pi/3 + 4/(2 Pi Abs[#]), #] & /@
    Range[-30, 30, .717]
   ]}, {theta, -6, 6}, PlotRange -> 40, PlotPoints -> 400,
 PlotStyle -> {{Thickness[.01]}, {Thickness[.01]}, Thickness[.01]}]

enter image description here

Exchanging some accuracy for performance:

PolarPlot[{4/Cos[theta], 4/Sin[theta],
  If[Pi/3 < theta < Pi/3 + .03, Range[-30, 30, .717]]
  }, {theta, -6, 6}, PlotRange -> 40, PlotPoints -> 400,
 PlotStyle -> {Thickness[.01], Thickness[.01], Thickness[.01]}]

enter image description here

I mention these to show how arbitrary your functions in Plots can be.

Here's one implementation of @Jonathan's idea:

PolarPlot[{4/Cos[theta], 4/Sin[theta], .2/(theta - Pi/3)},
 {theta, -2.1 Pi, 2.1 Pi}, PlotRange -> 40]

enter image description here

Another, flakier version:

PolarPlot[{4/Cos[theta], 4/Sin[theta], 10000 (theta - Pi/3)},
 {theta, -2.1 Pi, 2.1 Pi}, PlotRange -> 40]

enter image description here


You can use the option PolarGridLines to draw radial lines. For example:

PolarPlot[Cos[3 θ], {θ, 0, 2 π}, PolarGridLines->{{π/3},{}}]

enter image description here


Adding a straight line to a PolarPlot. To convert PolarPlot[r[θ],{θ,a,b}] to ParametricPlot use Parametric[r[θ]*Cos[θ],r[θ]*Sin[θ], then add your line.

Method 1: Just use parametric plot instead. Line is θ - Pi/3.

scalingFact = 5;
pPa = ParametricPlot[
  {{Sin[3 t] Cos[t], Sin[3 t] Sin[t]}, {Cos[Pi/3]*t, Sin[Pi/3]*t}/scalingFact}, {t, 0, Pi}, 
  PlotLabel -> "Parametric", ImageSize -> Tiny

Method 2: PolarPlot then ParametricPlot with line and Show both.

pPo = PolarPlot[{Red, Sin[3 t]}, {t, 0, Pi}, Mesh -> 10, 
 PlotLabel -> "Polar", ImageSize -> Tiny];

pPa = ParametricPlot[{Cos[Pi/3]*t, Sin[Pi/3]*t}/scalingFact, {t, 0, Pi}, 
 ImageSize -> Tiny];

Show[pPo, pPa, PlotStyle -> {{Red}, {Green}}]
  • $\begingroup$ my apologies obviously I am having trouble with this unusual editor. Could someone point me to some directions or a tutorial on how to input comments and code into this site properly. Thankyou $\endgroup$ – Larry Williams May 25 '18 at 6:07
  • $\begingroup$ mathematica.stackexchange.com/editing-help $\endgroup$ – Kuba May 25 '18 at 6:24

For lines that do not pass through the origin you can use the first argument of PolarPlot as follows:

PolarPlot[{4/Sin[theta], 4/Cos[theta], 10/(Sin[theta] + Cos[theta]), 
  10/(Sin[theta] - Cos[theta]), 20/(Sin[theta] + 3 Cos[theta])}, {theta, -3, 3}, 
 PlotRange -> {{-20, 20}, {-20, 20}}, PlotLegends -> "Expressions"]

enter image description here

To add lines that pass through the origin you can use Epilog as suggested by Rom38 in a comment or PolarGridLines as in Carl's answer.


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.