# Numeric string format for Makie plot?

**URL:** <https://discourse.julialang.org/t/numeric-string-format-for-makie-plot/87508>\
**Category:** Visualization\
**Tags:** question, makie, makielayout\
**Created:** [September 20, 2022, 9:12am UTC](https://discourse.julialang.org/t/numeric-string-format-for-makie-plot/87508 "2022-09-20T09:12:17Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![nvhoang.3110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nvhoang.3110/32/37168_2.png) [@nvhoang.3110](https://discourse.julialang.org/u/nvhoang.3110)\
**Post date:** [September 20, 2022, 9:12am UTC](https://discourse.julialang.org/t/numeric-string-format-for-makie-plot/87508/1 "2022-09-20T09:12:17Z")

</div>

Hello everyone! Sorry if my question is too basic for some people. Basically I’m trying to define the numeric string format for my Makie plot, specifically for the axis. The numbers on the y-axis that I want to display have the following format: `1,000,000.328`, where you have comma separator for every three number and decimal separator for the decimal portion. I’ve tried the Python number formatting, like `{:.3f}` or `{.,}`, but result is far from what I expect. Below is an example.

```julia
fig = Figure(resolution = (1920, 1080))

update_theme!(fontsize = 30)

axis = fig[1, 1] = Axis(fig, 
                        title = "An example",
                        ytickformat = "{:.3f}")

dat = DataFrame(x = 1:5, y = [1_000_000.236, 1_000_000.660, 1_000_000.368, 1_000_000.225, 1_000_000.224])

barplot!(axis, dat.x, dat.y)

fig

```

 ![example](https://global.discourse-cdn.com/julialang/original/3X/7/e/7e25eb3e06d529d81e9fc6e1ee0599a567f696c2.png)

So, is there any way to achieve my goal? Thank you in advance !

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [September 20, 2022, 10:42am UTC](https://discourse.julialang.org/t/numeric-string-format-for-makie-plot/87508/2 "2022-09-20T10:42:54Z")

</div>

Seems like `Formatting.jl` (which the format strings use in the background) doesn’t do this, you could try [GitHub - JuliaString/Format.jl: A Julia package to provide C and Python-like formatting support](https://github.com/JuliaString/Format.jl) instead.

---

<div class="post-metadata">

**Author:** ![nvhoang.3110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nvhoang.3110/32/37168_2.png) [@nvhoang.3110](https://discourse.julialang.org/u/nvhoang.3110)\
**Post date:** [September 20, 2022, 2:11pm UTC](https://discourse.julialang.org/t/numeric-string-format-for-makie-plot/87508/3 "2022-09-20T14:11:28Z")

</div>

Hi, thank you for your response. I’ve spent a couple of hours playing around with the package, it’s very handy. But yet, I still have no idea how to implement it with Makie, since it keeps raising error as invalid string format. Could you please make an example of using it with xticklabel or yticklabel ?

---

<div class="post-metadata">

**Author:** ![fatteneder](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fatteneder/32/33991_2.png) [@fatteneder](https://discourse.julialang.org/u/fatteneder)\
**Post date:** [September 20, 2022, 4:09pm UTC](https://discourse.julialang.org/t/numeric-string-format-for-makie-plot/87508/4 "2022-09-20T16:09:11Z")

</div>

Try

```julia
using CairoMakie
using Formatting
using DataFrames

fig = Figure()
update_theme!(fontsize = 30)
axis = fig[1,1] = Axis(fig,
                       title = "An examle",
                       ytickformat = v -> format.(v, commas=true, precision=3)
                        )
dat = DataFrame(x = 1:5, y = [1_000_000.236, 1_000_000.660, 1_000_000.368, 1_000_000.225, 1_000_000.224])
barplot!(axis, dat.x, dat.y)

save("mwe.png", fig)

```

which gives me

 ![image](https://global.discourse-cdn.com/julialang/original/3X/8/0/80b31620a8553ca290a023128805b5aaf1964b35.png)

---

<div class="post-metadata">

**Author:** ![jules](https://avatars.discourse-cdn.com/v4/letter/j/41988e/32.png) [@jules](https://discourse.julialang.org/u/jules)\
**Post date:** [September 20, 2022, 4:29pm UTC](https://discourse.julialang.org/t/numeric-string-format-for-makie-plot/87508/5 "2022-09-20T16:29:09Z")

</div>

Ah so it does work when using `format`, I just tried the format string syntax `"{:,.3f}"` which parses but doesn’t do anything.

---

<div class="post-metadata">

**Author:** ![nvhoang.3110](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nvhoang.3110/32/37168_2.png) [@nvhoang.3110](https://discourse.julialang.org/u/nvhoang.3110)\
**Post date:** [September 20, 2022, 5:10pm UTC](https://discourse.julialang.org/t/numeric-string-format-for-makie-plot/87508/6 "2022-09-20T17:10:44Z")

</div>

Thanks everyone for your help and responses 🙏 I really appreaciate ❤
