# How to Create Multiple Plots of Animation to Estimate Pi using Julia Plots or Luxor? Not with Pluto

**URL:** <https://discourse.julialang.org/t/how-to-create-multiple-plots-of-animation-to-estimate-pi-using-julia-plots-or-luxor-not-with-pluto/90765>\
**Category:** General Usage\
**Tags:** plotting\
**Created:** [November 24, 2022, 5:30pm UTC](https://discourse.julialang.org/t/how-to-create-multiple-plots-of-animation-to-estimate-pi-using-julia-plots-or-luxor-not-with-pluto/90765 "2022-11-24T17:30:25Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [November 24, 2022, 5:30pm UTC](https://discourse.julialang.org/t/how-to-create-multiple-plots-of-animation-to-estimate-pi-using-julia-plots-or-luxor-not-with-pluto/90765/1 "2022-11-24T17:30:25Z")

</div>

Hi all,

I want to try this, but do not want to use Pluto, is there any nice advice for me?

> **[Estimating π using polygons](https://towardsdatascience.com/estimating-%CF%80-using-polygons-d1a53a53f408)**
>
> Using Julia to play around with shapes and pies

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [November 24, 2022, 5:45pm UTC](https://discourse.julialang.org/t/how-to-create-multiple-plots-of-animation-to-estimate-pi-using-julia-plots-or-luxor-not-with-pluto/90765/2 "2022-11-24T17:45:03Z")

</div>

> [@Unable to use @bind from PlutoUI on Colab](https://discourse.julialang.org/t/unable-to-use-bind-from-plutoui-on-colab/90590/5):
>
> Well if you’re not running a Pluto notebook then you shouldn’t expect PlutoUI to work. If you want interactivity in a Jupyter notebook look at

---

<div class="post-metadata">

**Author:** ![cormullion](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cormullion/32/49131_2.png) [@cormullion](https://discourse.julialang.org/u/cormullion)\
**Post date:** [November 24, 2022, 6:34pm UTC](https://discourse.julialang.org/t/how-to-create-multiple-plots-of-animation-to-estimate-pi-using-julia-plots-or-luxor-not-with-pluto/90765/3 "2022-11-24T18:34:39Z")

</div>

More advice: don’t use Luxor for interactivity- unless you use, er, PlutoUI.

---

<div class="post-metadata">

**Author:** ![healyp](https://avatars.discourse-cdn.com/v4/letter/h/67e7ee/32.png) [@healyp](https://discourse.julialang.org/u/healyp)\
**Post date:** [November 24, 2022, 9:57pm UTC](https://discourse.julialang.org/t/how-to-create-multiple-plots-of-animation-to-estimate-pi-using-julia-plots-or-luxor-not-with-pluto/90765/4 "2022-11-24T21:57:43Z")

</div>

I’ve never understood why 3.14 was chosen as “pi day” when the 22nd of July, 22/7, is a better fit.

Apologies for veering off topic.

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [November 26, 2022, 7:41am UTC](https://discourse.julialang.org/t/how-to-create-multiple-plots-of-animation-to-estimate-pi-using-julia-plots-or-luxor-not-with-pluto/90765/5 "2022-11-26T07:41:01Z")

</div>

It is okay, it is a good logic to choose July 22nd

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [November 26, 2022, 8:38am UTC](https://discourse.julialang.org/t/how-to-create-multiple-plots-of-animation-to-estimate-pi-using-julia-plots-or-luxor-not-with-pluto/90765/6 "2022-11-26T08:38:50Z")

</div>

Maybe the code does not work, thus I do not want to use Pluto, rather use REPL instead

look at this warning and error I get for using the codes from the web above:

 ![Capture d’écran_2022-11-26_15-37-44](https://global.discourse-cdn.com/julialang/original/3X/d/2/d2d8529780ab59eaa3ceabb42ff4b4cbc7526e06.png)

that is by using Pluto…

---

<div class="post-metadata">

**Author:** ![Freya\_the\_Goddess](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/freya_the_goddess/32/36835_2.png) [@Freya\_the\_Goddess](https://discourse.julialang.org/u/Freya_the_Goddess)\
**Post date:** [November 26, 2022, 9:06am UTC](https://discourse.julialang.org/t/how-to-create-multiple-plots-of-animation-to-estimate-pi-using-julia-plots-or-luxor-not-with-pluto/90765/7 "2022-11-26T09:06:21Z")

</div>

Anyway great news I manage to plot it manually without interactivity, which is all I need currently. Interactivity can wait later on. After I get 128 GB of RAM in the future haha…

this is the working code if anyone wants to learn:

```julia
using Plots
gr()

function circumference_polygon(sides, radius=1.0)
	# inner angle
	α = 2π / sides
	# angle between side and vertex-center line
	β = (π - α) / 2
	
	# using law of sines
	side_length = radius * sin(α) / sin(β)

	return side_length * sides
end

function estimate_pi(sides)
	circumference = circumference_polygon(sides, 1.0)
	# as the circumference of the circle is 2rπ 
	return circumference / 2
end

function rotate_vector(v, α)
	x, y = v
	x2 = x * cos(α) - y * sin(α)
	y2 = x * sin(α) + y * cos(α)
	return (x2, y2)
end

function polygon_points(n)
	start_point = (0.0, 1.0)
	points = [start_point]
	internal_degree = 2π/n

	for i in 2:n
		last_point = points[end]
		new_point = rotate_vector(last_point, internal_degree)
		push!(points, new_point)
	end

	return points
end

#change the n_sides to any number you desire
n_sides = 3

pi_estimate = round(estimate_pi(n_sides), digits=5)

# plot a unit circle
plot(x -> sqrt(1 - x^2); color=:blue, aspect_ratio=1.0, legend=false)
plot!(x -> -sqrt(1 - x^2), color=:blue)
	
# plot the polygon
plot!(Shape(polygon_points(n_sides)), fillcolor=:green)
	
# annotate with sides and pi estimate
annotate!([(0, 0, ("n=$n_sides \n π̂=$pi_estimate", 20, :white, :center))])

```

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [November 26, 2022, 12:05pm UTC](https://discourse.julialang.org/t/how-to-create-multiple-plots-of-animation-to-estimate-pi-using-julia-plots-or-luxor-not-with-pluto/90765/8 "2022-11-26T12:05:06Z")

</div>

This is not a warning but an error, and imho it is pretty clearly stated plus there are even links you can click to automatically fix things for you - just click on either “Split this cell into 2 cells” or “Wrap all code in a begin … end block”

You’ve wrapped most of your code in `begin ... end`, but have another line of code (`using Plots`) in the same cell outside `begin ... end`
