# How to precisely control Plot size in mm?

**URL:** <https://discourse.julialang.org/t/how-to-precisely-control-plot-size-in-mm/87507>\
**Category:** General Usage\
**Tags:** question, plotting\
**Created:** [September 20, 2022, 8:54am UTC](https://discourse.julialang.org/t/how-to-precisely-control-plot-size-in-mm/87507 "2022-09-20T08:54:28Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JianghuiDu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jianghuidu/32/8028_2.png) [@JianghuiDu](https://discourse.julialang.org/u/JianghuiDu)\
**Post date:** [September 20, 2022, 8:54am UTC](https://discourse.julialang.org/t/how-to-precisely-control-plot-size-in-mm/87507/1 "2022-09-20T08:54:28Z")

</div>

How do I precisely control the size of the plot in mm?

```julia
using Plots
gr()
p = scatter(rand(100),randn(100), size = (1000,1000), dpi = 300, title = "rand", titlefontsize = 9)
savefig(p, "p.png")

```

Here I’m expecting the final size to be 8.47 cm, but it turns out to be ~46.8 cm on my computer. Is my estimation (1000/300\*2.54 cm) wrong?

Moreover, what happens when I save it as pdf, which doesn’t care about the `dpi`? `savefig(p, "p.pdf")` produced a file the size of which is 41.6 cm.

What about fontsize? The font in the pdf file looks like 15 pt rather than 9 pt.

Also, different backend gives completely different final size. That’s very confusing…

---

<div class="post-metadata">

**Author:** ![Gregstrq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gregstrq/32/20620_2.png) [@Gregstrq](https://discourse.julialang.org/u/Gregstrq)\
**Post date:** [September 20, 2022, 10:58am UTC](https://discourse.julialang.org/t/how-to-precisely-control-plot-size-in-mm/87507/2 "2022-09-20T10:58:22Z")

</div>

I think the size is measured internally in points. If you want some specific mm size, you need to convert mm to pt and then specify this number.

---

<div class="post-metadata">

**Author:** ![BeastyBlacksmith](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/beastyblacksmith/32/4741_2.png) [@BeastyBlacksmith](https://discourse.julialang.org/u/BeastyBlacksmith)\
**Post date:** [September 20, 2022, 11:14am UTC](https://discourse.julialang.org/t/how-to-precisely-control-plot-size-in-mm/87507/3 "2022-09-20T11:14:37Z")

</div>

The default unit is pixel, which means that the physical dimensions of the figure displayed on the screen depend on your screen and your resolution.  
Whereas the default unit for fontsizes is indeed pt.  
IIRC the GR backend does some upscaling using the dpi parameter to mimick an increase in resolution, which explains the bigger fontsize e.g. 9pt \* sqrt(3) ≈ 15pt.

---

<div class="post-metadata">

**Author:** ![JianghuiDu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jianghuidu/32/8028_2.png) [@JianghuiDu](https://discourse.julialang.org/u/JianghuiDu)\
**Post date:** [September 20, 2022, 7:18pm UTC](https://discourse.julialang.org/t/how-to-precisely-control-plot-size-in-mm/87507/4 "2022-09-20T19:18:40Z")

</div>

Where is this `sqrt(3)` coming from? And shouldn’t the saved file be independent of screen resolution? More specifically, where do I get the information of how the conversion works exactly? I can’t find it online.

---

<div class="post-metadata">

**Author:** ![Gregstrq](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gregstrq/32/20620_2.png) [@Gregstrq](https://discourse.julialang.org/u/Gregstrq)\
**Post date:** [January 23, 2023, 12:29pm UTC](https://discourse.julialang.org/t/how-to-precisely-control-plot-size-in-mm/87507/5 "2023-01-23T12:29:08Z")

</div>

> [@BeastyBlacksmith](#):
>
> The default unit is pixel, which means that the physical dimensions of the figure displayed on the screen depend on your screen and your resolution.

This is strange. I have created a figure using Plots.jl with GR backend and saved it to a pdf.  
Then, when I checked the properties of the pdf and converted the size to pt, it was equal to the figure size that I specified in plots. So, it looks like figures sizes are also measured in points.
