1
$\begingroup$

I imported a csv file, and the header of the columns are specific dates. How would I plot these points using ListPlot, but the x-axis instead of 1,2,3, etc, is the dates from the column headers? For example, the Header says 1/1/2020, 1/2/2020, and so on. How to make those the x-axis.

$\endgroup$
1
  • $\begingroup$ consider using DateListPlot instead of ListPlot? $\endgroup$
    – kglr
    Sep 3, 2020 at 7:18

1 Answer 1

1
$\begingroup$

You may use DateListPlot. Toward this aim do the following: Assume your data has the following form:

dat = {{"1/1/2020", "2/1/2020", "3/1/2020"}, {10, 20}, {15, 25}, {35, 
    45}};

You must first change the dates into DateObjects. Then you must assemble the individual time series. Finally you can plot them with DateListPlot:

dat = {{"1/1/2020", "2/1/2020", "3/1/2020"}, {10, 20}, {15, 25}, {35, 
    45}};
labels = DateObject /@ dat[[1]];
timeseries = Transpose[{labels, #}] & /@ Transpose[Rest[dat]]
DateListPlot[timeseries]
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.