# Plot a circle with a given radius with Plots.jl

**URL:** <https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295>\
**Category:** Visualization\
**Created:** [April 19, 2019, 7:49am UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295 "2019-04-19T07:49:22Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [April 19, 2019, 7:49am UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/1 "2019-04-19T07:49:22Z")

</div>

Hi,  
I can’t figure out how to plot circles with given radii.  
I would like the radius to be given as floats with plots units (not integers).  
I try to play with markersize but the display sizes do not correspond to xy units.  
Any hints?

Laurent

---

<div class="post-metadata">

**Author:** ![ffevotte](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ffevotte/32/6587_2.png) [@ffevotte](https://discourse.julialang.org/u/ffevotte)\
**Post date:** [April 19, 2019, 9:05am UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/2 "2019-04-19T09:05:13Z")

</div>

There might exist simpler solutions, but parametric curves probably cover your needs

> **[parametric function plot](https://goropikari.github.io/PlotsGallery.jl/src/parametric2d.html)**
>
> \[“These figures are made by Plots.jl”\]

---

<div class="post-metadata">

**Author:** ![mkborregaard](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mkborregaard/32/556_2.png) [@mkborregaard](https://discourse.julialang.org/u/mkborregaard)\
**Post date:** [April 19, 2019, 11:05am UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/3 "2019-04-19T11:05:07Z")

</div>

There is an unexported partialcircle function that can also plot a whole circle

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [April 19, 2019, 11:30am UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/4 "2019-04-19T11:30:01Z")

</div>

Thank you very much !

I came across partialcircle but I though that there might be an obvious solution like an annotation to express the markersize in plot units.

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [April 19, 2019, 11:34am UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/5 "2019-04-19T11:34:18Z")

</div>

Besides, partialcircle seems to take integer arguments… I will use the parametric function solution.

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [April 19, 2019, 2:01pm UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/6 "2019-04-19T14:01:27Z")

</div>

Hi,  
I usually use this.

 ![56](https://global.discourse-cdn.com/julialang/original/3X/e/1/e1d3351cfbad3f73483c5875c45739e97d21be1c.png)

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [April 19, 2019, 3:15pm UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/7 "2019-04-19T15:15:42Z")

</div>

Thank you, this is more elegant !

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [April 21, 2019, 5:45pm UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/8 "2019-04-21T17:45:39Z")

</div>

Ir rocks 😉 ![toto](https://global.discourse-cdn.com/julialang/original/3X/d/0/d05fed09ac4f08699f53f02a661ad10229534e72.gif)

---

<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:** [April 21, 2019, 7:56pm UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/9 "2019-04-21T19:56:12Z")

</div>

That’s very cool. Did you do this using Plots? Is the code available?

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [April 22, 2019, 7:33am UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/10 "2019-04-22T07:33:52Z")

</div>

Thanx !  
Yes it is Plots.  
At first I used Makie but we are preparing introductory Julia hands-on sessions and lately we experienced a lot of installation problems (Cairo?) that are difficult to handle on multiple heterogeneous student laptops.  
The code is not yet ready for sharing but it is mainly based on [Chris Hecker tutorial](http://chrishecker.com/images/e/e7/Gdmphys3.pdf).

The idea is to illustrates the power of Julia’s type system and multiple dispatch on a funny example. A hierarchy of 2D shapes and a bunch of methods for the contact function.

```julia
contact(c1::Circle,c2::Circle)
contact(p1::AbstractPolygon,p2::AbstractPolygon)
contact(p::AbstractPolygon,c::Circle)

```

The resulting Julia’s code is quite compact and performant and I think it gives a pretty convincing demonstration of Julia’s strength compared to other languages. In particular, for matlab users that may not be very experienced with types.

I still wonder about the best Julian way to handle multiple plotting backends (Makie/Plots) that prevents from depending on both packages (toml).

---

<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:** [April 22, 2019, 3:23pm UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/11 "2019-04-22T15:23:33Z")

</div>

Are you checking all pairwise collisions, or using one of the acceleration techniques like dividing into cells?

---

<div class="post-metadata">

**Author:** ![LaurentPlagne](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/laurentplagne/32/10103_2.png) [@LaurentPlagne](https://discourse.julialang.org/u/LaurentPlagne)\
**Post date:** [April 22, 2019, 3:55pm UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/12 "2019-04-22T15:55:37Z")

</div>

Yes. Keep in mind that it is a Julia lecture material and not a simulation package 😉

For the bigger time step, I use an N² overlap check on bounding boxes. From there, overlapping shapes recursively divide their time steps until true contact is reached. Then (hopefully) binary collisions are computed and velocities updated.This sequential code run rather smoothly up to 300 bodies.  
BTW I wonder how python or matlab experts would have implement this kind of code. I guess that recursive binary contact may not be that easy to express efficiently with “vectorized” (not SIMD) style…

---

<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:** [October 25, 2019, 2:06pm UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/13 "2019-10-25T14:06:21Z")

</div>

Is your code now available?

---

<div class="post-metadata">

**Author:** ![cjwyett](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/cjwyett/32/13345_2.png) [@cjwyett](https://discourse.julialang.org/u/cjwyett)\
**Post date:** [March 11, 2020, 3:38pm UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/14 "2020-03-11T15:38:49Z")

</div>

beautiful

---

<div class="post-metadata">

**Author:** ![bonzobavaria](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/bonzobavaria/32/16125_2.png) [@bonzobavaria](https://discourse.julialang.org/u/bonzobavaria)\
**Post date:** [July 3, 2020, 8:59pm UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/15 "2020-07-03T20:59:23Z")

</div>

That is so helpful! Thank you.

---

<div class="post-metadata">

**Author:** ![lazarusA](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/lazarusa/32/6571_2.png) [@lazarusA](https://discourse.julialang.org/u/lazarusA)\
**Post date:** [July 5, 2020, 10:26pm UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/16 "2020-07-05T22:26:34Z")

</div>

Take a look at [https://lazarusa.github.io/gnuplot-examples/](https://lazarusa.github.io/gnuplot-examples/) (any suggestions are welcome, I do have a lot of examples around). I just need to know what the community is looking for. Cheers !

---

<div class="post-metadata">

**Author:** ![Norbert-droid](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/norbert-droid/32/20364_2.png) [@Norbert-droid](https://discourse.julialang.org/u/Norbert-droid)\
**Post date:** [July 26, 2020, 6:52pm UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/17 "2020-07-26T18:52:49Z")

</div>

Thanks

---

<div class="post-metadata">

**Author:** ![Ahmed\_Salih](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ahmed_salih/32/206579_2.png) [@Ahmed\_Salih](https://discourse.julialang.org/u/Ahmed_Salih)\
**Post date:** [October 9, 2021, 8:37am UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/18 "2021-10-09T08:37:14Z")

</div>

How would I plot this shape in 3d? Imagine a circular plane

Kind regards

---

<div class="post-metadata">

**Author:** ![rafael.guerra](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rafael.guerra/32/216610_2.png) [@rafael.guerra](https://discourse.julialang.org/u/rafael.guerra)\
**Post date:** [October 9, 2021, 9:38am UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/19 "2021-10-09T09:38:43Z")

</div>

Linking related posts for some 3D disk solutions using [Plots.jl](https://discourse.julialang.org/t/plots-circle-in-3d-space/64121) and [Makie.jl](https://discourse.julialang.org/t/plotting-an-ellipsoid-as-2d-surface-in-3d-given-the-principal-axes/60393).

---

<div class="post-metadata">

**Author:** ![tdunning](https://avatars.discourse-cdn.com/v4/letter/t/13edae/32.png) [@tdunning](https://discourse.julialang.org/u/tdunning)\
**Post date:** [July 16, 2022, 11:02pm UTC](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295/20 "2022-07-16T23:02:07Z")

</div>

@LaurentPlagne

Did you ever finish this code well enough to release it?

[Next page](https://discourse.julialang.org/t/plot-a-circle-with-a-given-radius-with-plots-jl/23295.md?page=2)
