Message Boards Message Boards

0
|
5426 Views
|
3 Replies
|
2 Total Likes
View groups...
Share
Share this post:

[?] Specify the FrameTicks in DateListPlot every year?

Posted 7 years ago

Dear Community,

The default "FrameTicks" are split every two years in DateListPlot. How can I split in every year?

Example 2006, 2007, 2008, 2009, 2010,......,2016 and not 2006, 2008, 2010, 2012, 2014, 2016. I have tried a number of options, but none of these are working. (* See options in code *)

fakedata = {{{2006, 1, 1}, 27}, {{2006, 2, 2}, 25}, {{2006, 3, 3}, 
   86}, {{2006, 4, 4}, 72}, {{2006, 5, 5}, 66}, {{2006, 6, 6}, 
   18}, {{2006, 7, 7}, 13}, {{2006, 8, 8}, 7}, {{2006, 9, 9}, 
   84}, {{2006, 10, 10}, 0}, {{2006, 11, 11}, 19}, {{2006, 12, 12}, 
   50},

  {{2007, 1, 1}, 8}, {{2007, 1, 2}, 72}, {{2007, 1, 3}, 
   8}, {{2007, 2, 4}, 45}, {{2007, 2, 5}, 0}, {{2007, 2, 6}, 
   8}, {{2007, 3, 7}, 9}, {{2007, 3, 8}, 30}, {{2007, 3, 9}, 
   63}, {{2007, 3, 10}, 16}, {{2007, 4, 11}, 11},

  {{2015, 1, 1}, 14}, {{2015, 12, 2}, 75}, {{2015, 3, 3}, 
   28}, {{2015, 4, 4}, 10}, {{2015, 5, 5}, 31}, {{2015, 6, 6}, 
   75}, {{2015, 7, 7}, 16}, {{2015, 8, 8}, 79}, {{2015, 9, 9}, 
   19}, {{2015, 10, 10}, 86}, {{2015, 11, 11}, 81}, {{2015, 12, 12}, 
   25}
  }

DateListPlot[fakedata
 , GridLines -> Automatic
 , GridLinesStyle -> Directive[Black, Dotted]
 , ImageSize -> 600
 , AspectRatio -> 1/5
 , FrameTicks -> {{Automatic, None}, {Automatic, None}}
 , DateTicksFormat -> {"Year"}
 ]
(* Options:
 FrameTicks\[Rule]{True{Range[2006,2015,1]//Evaluate,Automatic}}

or

FrameTicks\[Rule]{{{1,"2006"},{2,"2007"},{3,"2008"},{4,"2009"},{5,\
"2010"},{6,"2011"},{7,"2012"},{8,"2013"},{9,"2014"},{10,"2015"}},\
Automatic} *)

enter image description here

Please can you help !

Best Regards,...Jos

POSTED BY: Jos Klaps
3 Replies

Jos,

My response to this post might also help with what you are doing

POSTED BY: Neil Singer

Hi Neil,

Thanks for your excellent support and nice example "plot with dynamic plotrange". This is really appreciated !

Best Regards,....Jos

POSTED BY: Jos Klaps

Jos,

you need to specify the frameticks in this format. Obviously you can create a clever function to automatically generate the required list. I just typed in January first of every year.

DateListPlot[fakedata, GridLines -> Automatic, 
 GridLinesStyle -> Directive[Black, Dotted], ImageSize -> 600, 
 AspectRatio -> 1/5, 
 FrameTicks -> {Automatic, {{{2006, 1, 1}, {2007, 1, 1}, {2008, 1, 
      1}, {2009, 1, 1}, {2010, 1, 1}, {2011, 1, 1}, {2012, 1, 
      1}, {2013, 1, 1}, {2014, 1, 1}, {2015, 1, 1}, {2016, 1, 1}}, 
    None}}, DateTicksFormat -> {"Year"}]

enter image description here

Regards,

Neil

POSTED BY: Neil Singer
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract