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

Consider this piece of code:

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:

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?

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

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

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

I’ve submitted an issue.

The following might be of interest in some use cases:

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