4
$\begingroup$

I want to plot in the {Month,Day} time format, but the DateListPlot function seems to only accept the {Year, Month, Day} format. What can I do to draw the time image correctly?

data={{{1, 20}, 269.`}, {{1, 21}, 403.`}, {{1, 22}, 523.`}, {{1, 23}, 
  783.`}, {{1, 24}, 1183.`}, {{1, 25}, 1796.`}, {{1, 26}, 
  2528.`}, {{1, 27}, 4172.`}, {{1, 28}, 6496.`}, {{1, 29}, 
  8531.`}, {{1, 30}, 10642.`}, {{1, 31}, 12978.`}, {{2, 1}, 
  15232.`}, {{2, 2}, 17697.`}, {{2, 3}, 20522.`}, {{2, 4}, 
  23614.`}, {{2, 5}, 27426.`}, {{2, 6}, 31029.`}, {{2, 7}, 
  34038.`}, {{2, 8}, 37346.`}, {{2, 9}, 42508.`}, {{2, 10}, 
  45767.`}, {{2, 11}, 47609.`}, {{2, 12}, 49082.`}, {{2, 13}, 
  62170.`}}
DateListPlot[%]
$\endgroup$
8
$\begingroup$

Use the option DateFunction

DateListPlot[data, DateFunction :> (Prepend[#, 2020] &)]

or prepend the {month, day} pairs with an arbitrary year:

DateListPlot[MapAt[Prepend[#, 2020] &, data, {All, 1}]]

to get

enter image description here

$\endgroup$
3
$\begingroup$

Or another variant:

DateListPlot[ReplacePart[#, 1 -> Prepend[#[[1]], 2020]] & /@ data]
$\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.