4
$\begingroup$

MMA 12. Many XY-style plot functions support the Filling option, so that e.g Filling->Axis drops a line from every plot point to the X axis, or may be used to fill the area between the line and the axis (just one use of a few kinds these options offer).

When I ask Wolfram Alpha to plot the roots of the equation $z^{11}+1=0$, there is a nice plot down the page with filling lines to the origin:

enter image description here

I want the draw the same lines in MMA (likely using the ComplexListPlot function), but I cannot find an easy way to do that. Perhaps, massaging the source list into Directives or something even less elegant like that would get the job done, but I suspect that I am missing something simple.

What is the simplest way to draw filling lines from discrete plot points in the complex plane to the origin? I'm starting at this simple drawing

ComplexListPlot[z /. Solve[z^11 + 1 == 0, z], 
   PlotStyle -> {Red, AbsolutePointSize[6]}, 
   Prolog -> {GrayLevel[0.8], Circle[]}]

to reproduce the Alpha's plot (sans the box and axis labels, but that's trivial to add). It's the radial lines that got me bamboozled by how ostensibly unsimple they are to render.

enter image description here

$\endgroup$

2 Answers 2

5
$\begingroup$
lst = z /. Solve[z^11 + 1 == 0, z];

1. Add the desired lines into Prolog:

ComplexListPlot[lst, PlotStyle -> {Red, AbsolutePointSize[6]}, 
   Prolog -> {GrayLevel[0.8], Circle[], Line[{{0,0}, #} &/@ ReIm[lst]]}]

enter image description here

Further alternatives:

2. Post-process to inject the desired lines:

ComplexListPlot[lst, PlotStyle -> {Red, AbsolutePointSize[6]}, 
  BaseStyle -> GrayLevel[.8],  Prolog -> Circle[]] // 
    Normal[#] /. {d_Directive, p_Point} :> { Line[{{0, 0}, #}] & /@ First[p], d, p} &

enter image description here

3. Create a second plot with input Thread[{0, lst}] and the option Joined -> True and combine it with the original plot using Show:

Show[ComplexListPlot[Thread[{0, lst}], Joined -> True,  PlotStyle -> GrayLevel[0.8]], 
 ComplexListPlot[lst, PlotStyle -> {Red, AbsolutePointSize[6]}],
 Prolog -> {GrayLevel[0.8], Circle[]}]

blah

$\endgroup$
1
  • 1
    $\begingroup$ Thanks, I was thinking along the lines of the 2nd solution, and mentally labeled as quite ugly, but the first one looks much cleaner and more versatile: all the Graphics directives are directly available to style the lines, and the lines are just lines, not repurposed polar gridlines, so I perceive your first one as the cleanest approach of the three so far. I'm certainty upvoting both, they all are sensible. Let me linger on the green mark for a day tho. $\endgroup$ Sep 16, 2020 at 4:55
6
$\begingroup$

The ComplexListPlot just some type of PolarPlot, so we can using PolarGridLines to add lines.

For a list of complex points, we can use Arg to get the polar angle.

Update

pts = z /. Solve[z^11 + 1 == 0, z];
ComplexListPlot[pts, PlotStyle -> {Red, AbsolutePointSize[6]}, 
 PolarAxesOrigin -> {0, 1}, PolarGridLines -> {Arg[pts], {1}}, 
 GridLinesStyle -> Gray, Frame -> True]

Original

ComplexListPlot[z /. Solve[z^11 + 1 == 0, z], 
 PlotStyle -> {Red, AbsolutePointSize[6]}, 
 PolarAxesOrigin -> {Pi/11, 1}, 
 PolarGridLines -> {Table[i*Pi/11, {i, 1, 22, 2}], {1}}, 
 GridLinesStyle -> Gray, Frame -> True]

enter image description here

$\endgroup$
6
  • $\begingroup$ I wonder if there’s a way to add them “automatically”, as it seems the method for this solution would have to be rebuilt for each function? $\endgroup$ Sep 16, 2020 at 0:55
  • $\begingroup$ @CATrevillian, looks like it, but it's easy to wrap into a function if that's going to be reused often. $\endgroup$ Sep 16, 2020 at 2:09
  • 1
    $\begingroup$ I do not understand the PolarAxesOrigin -> {Pi/11, 1} part. To me, PolarAxesOrigin -> {0, 1} does seems to work the same. $\endgroup$ Sep 16, 2020 at 2:23
  • $\begingroup$ @cvmgt, thanks, I got the general idea to use gridlines for this visualization. I'll hold off the green check for a day or two, in case another interesting solution pops up. May I suggest keeping only the "Update" solution? The update history within the answer looks confusing a bit, and is visible on SE anyway, via the Edit link. $\endgroup$ Sep 16, 2020 at 2:41
  • $\begingroup$ @kkm If we set PolarAxes -> True we can find the difference between PolarAxesOrigin -> {Pi/11, 1} and PolarAxesOrigin -> {0, 1} $\endgroup$
    – cvgmt
    Sep 16, 2020 at 3:01

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.