# Format ticks : add 'km' at the end

**URL:** <https://community.plotly.com/t/format-ticks-add-km-at-the-end/60932>\
**Category:** 📊 Plotly Python\
**Tags:** question\
**Created:** [February 13, 2022, 2:09am UTC](https://community.plotly.com/t/format-ticks-add-km-at-the-end/60932 "2022-02-13T02:09:03Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![dataturnsmeon](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dataturnsmeon](https://community.plotly.com/u/dataturnsmeon)\
**Post date:** [February 13, 2022, 2:09am UTC](https://community.plotly.com/t/format-ticks-add-km-at-the-end/60932/1 "2022-02-13T02:09:03Z")

</div>

Hi community,

I want the plot axes tick to be formatted as ‘100km’ or ‘1000m’. I know that plotly supports D3 number formatting, there are examples of adding prefix and symbols in the documentation but I couldn’t find a way to add a postfix to the numbers.

If anyone can help me out here, I’ll be very greatful.

Thanks 🙂

---

<div class="post-metadata">

**Author:** ![RenaudLN](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/renaudln/32/9041_2.png) [@RenaudLN](https://community.plotly.com/u/RenaudLN)\
**Post date:** [February 13, 2022, 11:22am UTC](https://community.plotly.com/t/format-ticks-add-km-at-the-end/60932/2 "2022-02-13T11:22:49Z")

</div>

Hi @dataturnsmeon you can add suffix to axes ticks as follow:

```python
fig.update_layout(
    # on the y-axis
    yaxis_ticksuffix="m",
    # on the colorbar
    coloraxis_colorbar_ticksuffix="m",
    # To specify which tick should have suffix
    yaxis_showticksuffix="all" # or "first" or "last"
)

```

See the [reference](https://plotly.com/python/reference/layout/yaxis/) for more info.

You cannot have a suffix that changes for metres and kilometres but you could take advantage of the fact that D3 can do power of 1000 suffix (default behaviour for numeric ticks).

---

<div class="post-metadata">

**Author:** ![dataturnsmeon](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dataturnsmeon](https://community.plotly.com/u/dataturnsmeon)\
**Post date:** [February 14, 2022, 5:04am UTC](https://community.plotly.com/t/format-ticks-add-km-at-the-end/60932/3 "2022-02-14T05:04:43Z")

</div>

Thanks @RenaudLN !

---

<div class="post-metadata">

**Author:** ![dataturnsmeon](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dataturnsmeon](https://community.plotly.com/u/dataturnsmeon)\
**Post date:** [February 21, 2022, 7:37pm UTC](https://community.plotly.com/t/format-ticks-add-km-at-the-end/60932/4 "2022-02-21T19:37:23Z")

</div>

@RenaudLN

Sorry to bother you again, but do you know how to replace “,” (comma) separator to “.” (dot) for thousands?  
Eg: 100,000 → 100.000

In D3 we can use locale formatter but I don’t think that’s supported with plotly.

---

<div class="post-metadata">

**Author:** ![atharvakatre](https://sea2.discourse-cdn.com/flex024/user_avatar/community.plotly.com/atharvakatre/32/14713_2.png) [@atharvakatre](https://community.plotly.com/u/atharvakatre)\
**Post date:** [February 23, 2022, 9:27am UTC](https://community.plotly.com/t/format-ticks-add-km-at-the-end/60932/5 "2022-02-23T09:27:04Z")

</div>

Hi @dataturnsmeon,

I am not sure if there’s an easy way to do this with D3 formatting, but I know a workaround that you can use in your python code.

In the below example I am setting the start, end and step-size for the ticks on y axis and by using string formatting I am just replacing the comma with a period.

```auto
import plotly.express as px

data_canada = px.data.gapminder().query("country == 'Canada'")
fig = px.bar(data_canada, x='year', y='pop')

t_start = 0
t_end = 35000000
t_diff = 5000000
fig.update_yaxes(
    range=[t_start, t_end],
    dtick=t_diff,
    tickvals=[x for x in range(0, t_end + t_diff, t_diff)],
    ticktext=[
        "{:,}".format(x).replace(",", ".") for x in range(0, t_end + t_diff, t_diff)
    ],
    tickmode="array",
)

fig.show()

```

 ![newplot](https://us1.discourse-cdn.com/flex024/uploads/plot/original/3X/8/a/8a1073d3098f4312ca8427c48704d9c44aed5f34.png)

Hope this helps 🙂

---

<div class="post-metadata">

**Author:** ![dataturnsmeon](https://avatars.discourse-cdn.com/v4/letter/d/4af34b/32.png) [@dataturnsmeon](https://community.plotly.com/u/dataturnsmeon)\
**Post date:** [February 23, 2022, 9:38am UTC](https://community.plotly.com/t/format-ticks-add-km-at-the-end/60932/6 "2022-02-23T09:38:56Z")

</div>

Wow ! Nice trick.  
Thanks a lot @atharvakatre, this absolutely works for me.
