# Plot line segments (e.g. n-th roots on unit circle ) in polar projection

**URL:** <https://discourse.julialang.org/t/plot-line-segments-e-g-n-th-roots-on-unit-circle-in-polar-projection/17322>\
**Category:** General Usage\
**Created:** [November 8, 2018, 8:45pm UTC](https://discourse.julialang.org/t/plot-line-segments-e-g-n-th-roots-on-unit-circle-in-polar-projection/17322 "2018-11-08T20:45:08Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![haigenw](https://avatars.discourse-cdn.com/v4/letter/h/439d5e/32.png) [@haigenw](https://discourse.julialang.org/u/haigenw)\
**Post date:** [November 8, 2018, 8:45pm UTC](https://discourse.julialang.org/t/plot-line-segments-e-g-n-th-roots-on-unit-circle-in-polar-projection/17322/1 "2018-11-08T20:45:08Z")

</div>

Question:

1. How to plot n-th roots on the unit circle in polar projection in Julia? Is this the intended/natural way to do it, or is there any better/lighter-weight way than the following?

2. How to plot “π/6” instead of the value of θ in plot title and in annotations?

```julia
# Plot line segment (e.g. n-th roots on unit circle) in polar prejection
using Plots; gr()

# set step size θ
θ = π/6

# plot points at angle θ at step size π/6 from 0 to 2π, points on the circle NOT to be beconnected, a way to do that is
# plot one root at a time as a segment with first end point at orign [0,0], and second end point at [i*π/6,1].

b1=Float64[1:2;].-1.0

# Q(3): how to plot "π/6" instead of the value of θ in plot title and in annotations?
plt = plot(proj=:polar, m=0, title="polar projection step size $θ")
for i in 1:Int64(2π/θ)
    # with marker point size m=5
    plot!(plt, 0:i*θ:i*θ, b1, m=5, annotations=(b1[2]*cos(i*θ), b1[2]*sin(i*θ), text("$i π/6", :left)))
end

# return the plot object, won't display without this
plt

# plotted graph is attached below

```

 ![plotpolar1](https://global.discourse-cdn.com/julialang/original/3X/4/d/4de90078fa6c58fd9c63c5a0cd7f7036736f20cd.jpeg)

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [November 8, 2018, 8:49pm UTC](https://discourse.julialang.org/t/plot-line-segments-e-g-n-th-roots-on-unit-circle-in-polar-projection/17322/2 "2018-11-08T20:49:21Z")

</div>

I’ve edited your post to make it considerably less shouty.

> [@PSA: how to quote code with backticks](https://discourse.julialang.org/t/psa-how-to-quote-code-with-backticks/7530):
>
> This is a short post on how to use backticks (` and ```) to quote code, so it is easy to read. This post can be linked to new users who are confused by this feature. Why By quoting your code, you get a monospaced font (which preserves indentation) and syntax highlighting. This makes it easier to read your code and help you. Displayed code looks like this: function displayed\_code(x::Int, y::Int) if x \< y println("x is smaller") else println("or not") end end Inline…

---

<div class="post-metadata">

**Author:** ![haigenw](https://avatars.discourse-cdn.com/v4/letter/h/439d5e/32.png) [@haigenw](https://discourse.julialang.org/u/haigenw)\
**Post date:** [November 8, 2018, 8:57pm UTC](https://discourse.julialang.org/t/plot-line-segments-e-g-n-th-roots-on-unit-circle-in-polar-projection/17322/3 "2018-11-08T20:57:40Z")

</div>

Thank you very much for letting me know this. I was wondering how to do it, but wasn’t patient enough to figure out.

---

<div class="post-metadata">

**Author:** ![dpsanders](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dpsanders/32/3573_2.png) [@dpsanders](https://discourse.julialang.org/u/dpsanders)\
**Post date:** [November 8, 2018, 10:24pm UTC](https://discourse.julialang.org/t/plot-line-segments-e-g-n-th-roots-on-unit-circle-in-polar-projection/17322/4 "2018-11-08T22:24:18Z")

</div>

The for loop returns nothing. You need to return the plot object.

Another way is to start off with p = plot()  
and then put

p

as the last line in order to return that object.

---

<div class="post-metadata">

**Author:** ![haigenw](https://avatars.discourse-cdn.com/v4/letter/h/439d5e/32.png) [@haigenw](https://discourse.julialang.org/u/haigenw)\
**Post date:** [November 8, 2018, 10:41pm UTC](https://discourse.julialang.org/t/plot-line-segments-e-g-n-th-roots-on-unit-circle-in-polar-projection/17322/5 "2018-11-08T22:41:21Z")

</div>

Thank you very much. Worked with your suggestion. Tried the code with plot object plt in the plot! and without, it didn’t change the outcome - I figured it was because plot! made the system to look for the most recent plot object to modify on.

```julia
plt = plot(proj=:polar, m=0, title="polar projection step size $θ")
for i in 1:Int64(2π/θ)
    # with marker point size m=5
    plot!(plt, 0:i*π/6:i*π/6, b1, m=5, annotations=(b1[2]*cos(i*π/6), b1[2]*sin(i*π/6), text("$i π/6", :left)))
end
plt

```
