Putting Date objects on xticks using Plots.jl


I tried to make a plot using Plots with dates under the ticks of the x axis but I ran into a problem. The dates are displayed in the plot in this format: yyyy/mm/ddT00:00:00. Does anyone know how to get rid of this? Here is the code I used.

using Dates
using Plots

date_strings = [“1/22/20”, “2/22/20”, “3/22/20”, “4/22/20”, “5/22/20”]
data = [1, 2, 3, 4, 5]

format = Dates.DateFormat(“m/d/Y”)
dates = parse.(Date, date_strings, format) .+ Year(2000)

plot(dates, data, xticks=dates[1:end], rotation=45)


You can use the Dates.format method to do that. In your example:

plot(dates, data; xticks=(dates, Dates.format.(dates, "m/d/yyyy")), rotation=45)


Thank you :slight_smile: