Trying to use plotly js to make a plot of dates, but for some reason it is showing time and date.
How can I remove time from this plot? Thanks!
x = ["2023-02-13", "2023-02-14"];
y = [3, 4];
var trace1 = {
type: "scatter",
mode: "lines",
name: '',
x: x,
y: y,
line: {color: '#17BECF'}
}
var layout = {
xaxis: {
type: 'date',
},
title: '',
};
var data = [trace1];
Plotly.newPlot('plotDiv', data, layout);

We can specify the tickformat in the xaxis of the layout with tickformat: '%b %d, %Y' to avoid including the time. And to avoid having the same date repeat on multiple ticks for the same day, we can also set the distance between ticks to be 1 day using dtick: 86400000.0 (which will be in units of seconds according to the documentation).
The codepen can be viewed here.
var layout = {
xaxis: {
type: 'date',
tickformat: '%b %d, %Y',
dtick: 86400000.0
},
title: '',
};

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With