# Can't format plot ticks when Dates or strings are used as input

**URL:** <https://discourse.julialang.org/t/cant-format-plot-ticks-when-dates-or-strings-are-used-as-input/103185>\
**Category:** General Usage\
**Tags:** plotting, strings, dates, formatting\
**Created:** [August 25, 2023, 10:48am UTC](https://discourse.julialang.org/t/cant-format-plot-ticks-when-dates-or-strings-are-used-as-input/103185 "2023-08-25T10:48:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ultrapoci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ultrapoci/32/25356_2.png) [@ultrapoci](https://discourse.julialang.org/u/ultrapoci)\
**Post date:** [August 25, 2023, 10:48am UTC](https://discourse.julialang.org/t/cant-format-plot-ticks-when-dates-or-strings-are-used-as-input/103185/1 "2023-08-25T10:48:09Z")

</div>

Consider this piece of code:

```julia
using Plots
plot(1:10, rand(10), xformatter = x -> "asd")

```

This correctly produces a plot where the ticks on the X axis are all the string “asd”.

If we instead do this:

```julia
using Plots
plot(string.(1:10), rand(10), xformatter = x -> "asd")

```

The X axis is not formatted anymore: the ticks are the number 1 to 10. The same happens if instead of strings, I use Date/Time/DateTime objects. How can I format plot ticks when using these objects?

---

<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:** [August 25, 2023, 10:53am UTC](https://discourse.julialang.org/t/cant-format-plot-ticks-when-dates-or-strings-are-used-as-input/103185/2 "2023-08-25T10:53:20Z")

</div>

Might be worth an issue, that doesn’t seem right.

The simplest workaround is probably just directly providing the ticks and ticklabels:

```julia
plot(string.(1:10), rand(10), xticks = (1:10, fill("asd",10)))

```

---

<div class="post-metadata">

**Author:** ![ultrapoci](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ultrapoci/32/25356_2.png) [@ultrapoci](https://discourse.julialang.org/u/ultrapoci)\
**Post date:** [August 31, 2023, 8:01am UTC](https://discourse.julialang.org/t/cant-format-plot-ticks-when-dates-or-strings-are-used-as-input/103185/4 "2023-08-31T08:01:12Z")

</div>

I’ve submitted an [issue](https://github.com/JuliaPlots/Plots.jl/issues/4817).

---

<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:** [August 31, 2023, 9:07am UTC](https://discourse.julialang.org/t/cant-format-plot-ticks-when-dates-or-strings-are-used-as-input/103185/5 "2023-08-31T09:07:21Z")

</div>

The following might be of interest in some use cases:

```julia
plot(string.(1:9) .|> x -> "asd_"*x, rand(9))

```
