{"id":2549,"date":"2010-04-09T11:25:07","date_gmt":"2010-04-09T11:25:07","guid":{"rendered":"https:\/\/blogs.mathworks.com\/pick\/2010\/04\/09\/dynamic-date-ticks\/"},"modified":"2010-04-09T11:25:07","modified_gmt":"2010-04-09T11:25:07","slug":"dynamic-date-ticks","status":"publish","type":"post","link":"https:\/\/blogs.mathworks.com\/pick\/2010\/04\/09\/dynamic-date-ticks\/","title":{"rendered":"Dynamic Date Ticks"},"content":{"rendered":"<div xmlns:mwsh=\"https:\/\/www.mathworks.com\/namespace\/mcode\/v1\/syntaxhighlight.dtd\" class=\"content\">\r\n   <p><a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\">Jiro<\/a>'s pick this week is <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27075-intelligent-dynamic-date-ticks\">Dynamic Date Ticks<\/a> by our fellow MathWorker (and an Application Engineer) <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/31422\">Ameya<\/a>. If you work with time series data, this is a must-have utility.\r\n   <\/p>\r\n   <p>Have you ever wanted to plot a graph with dates along the x-axis? MATLAB has had a function called <tt><a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/ref\/datetick.html\">datetick<\/a><\/tt> for a long time, and it gives you a nice set of tick labels with date strings. But often times, you may want to interact\r\n      with your plot by zooming and panning. Since <tt>datetick<\/tt> fixes the tick labels at the time of creation, the labels may disappear if you zoom in too far or pan away from the original\r\n      limits. There are techniques you can employ to automatically update the tick labels after <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/ref\/zoom.html\">zooming<\/a> and <a href=\"https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/ref\/pan.html\">panning<\/a>, or you can use Ameya's <tt>dynamicDateTicks<\/tt>.\r\n   <\/p>\r\n   <p>Actually, there are a <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=tag%3A%22datetick%22\">few entries<\/a> on the File Exchange that provide automatic update of dateticks, one of which was selected as a <a href=\"https:\/\/blogs.mathworks.com\/pick\/2007\/07\/06\/adaptive-date-ticks\/\">Pick of the Week<\/a>. Most of them leverage the callback behaviors of zoom and pan. What's unique about Ameya's function is that not only does\r\n      it dynamically update the tick labels as you zoom and pan, it also shows year or day changes (so you always have the full\r\n      date information), and displays data tips appropriately.\r\n   <\/p>\r\n   <p><img decoding=\"async\" vspace=\"5\" hspace=\"5\" src=\"https:\/\/blogs.mathworks.com\/images\/pick\/dynamicdateticks_screenshot.png\"> <\/p>\r\n   <p><b>Comments<\/b><\/p>\r\n   <p>Give this a try and <a href=\"https:\/\/blogs.mathworks.com\/pick\/?p=2549#respond\">tell us<\/a> what you think, or leave a comment for Ameya on the <a href=\"https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27075-intelligent-dynamic-date-ticks\">submission page<\/a>.\r\n   <\/p><script language=\"JavaScript\">\r\n<!--\r\n\r\n    function grabCode_e5374933306c4607ab1631fdbcdc9658() {\r\n        \/\/ Remember the title so we can use it in the new page\r\n        title = document.title;\r\n\r\n        \/\/ Break up these strings so that their presence\r\n        \/\/ in the Javascript doesn't mess up the search for\r\n        \/\/ the MATLAB code.\r\n        t1='e5374933306c4607ab1631fdbcdc9658 ' + '##### ' + 'SOURCE BEGIN' + ' #####';\r\n        t2='##### ' + 'SOURCE END' + ' #####' + ' e5374933306c4607ab1631fdbcdc9658';\r\n    \r\n        b=document.getElementsByTagName('body')[0];\r\n        i1=b.innerHTML.indexOf(t1)+t1.length;\r\n        i2=b.innerHTML.indexOf(t2);\r\n \r\n        code_string = b.innerHTML.substring(i1, i2);\r\n        code_string = code_string.replace(\/REPLACE_WITH_DASH_DASH\/g,'--');\r\n\r\n        \/\/ Use \/x3C\/g instead of the less-than character to avoid errors \r\n        \/\/ in the XML parser.\r\n        \/\/ Use '\\x26#60;' instead of '<' so that the XML parser\r\n        \/\/ doesn't go ahead and substitute the less-than character. \r\n        code_string = code_string.replace(\/\\x3C\/g, '\\x26#60;');\r\n\r\n        author = 'Jiro Doke';\r\n        copyright = 'Copyright 2010 The MathWorks, Inc.';\r\n\r\n        w = window.open();\r\n        d = w.document;\r\n        d.write('<pre>\\n');\r\n        d.write(code_string);\r\n\r\n        \/\/ Add author and copyright lines at the bottom if specified.\r\n        if ((author.length > 0) || (copyright.length > 0)) {\r\n            d.writeln('');\r\n            d.writeln('%%');\r\n            if (author.length > 0) {\r\n                d.writeln('% _' + author + '_');\r\n            }\r\n            if (copyright.length > 0) {\r\n                d.writeln('% _' + copyright + '_');\r\n            }\r\n        }\r\n\r\n        d.write('<\/pre>\\n');\r\n      \r\n      d.title = title + ' (MATLAB code)';\r\n      d.close();\r\n      }   \r\n      \r\n-->\r\n<\/script><p style=\"text-align: right; font-size: xx-small; font-weight:lighter;   font-style: italic; color: gray\"><br><a href=\"javascript:grabCode_e5374933306c4607ab1631fdbcdc9658()\"><span style=\"font-size: x-small;        font-style: italic;\">Get \r\n            the MATLAB code \r\n            <noscript>(requires JavaScript)<\/noscript><\/span><\/a><br><br>\r\n      Published with MATLAB&reg; 7.10<br><\/p>\r\n<\/div>\r\n<!--\r\ne5374933306c4607ab1631fdbcdc9658 ##### SOURCE BEGIN #####\r\n%%\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/15007\r\n% Jiro>'s pick this week is\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27075-intelligent-dynamic-date-ticks\r\n% Dynamic Date Ticks> by our fellow MathWorker (and an Application\r\n% Engineer)\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/authors\/31422\r\n% Ameya>. If you work with time series data, this is a must-have utility.\r\n%\r\n% Have you ever wanted to plot a graph with dates along the x-axis? MATLAB\r\n% has had a function called\r\n% |<https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/ref\/datetick.html\r\n% datetick>| for a long time, and it gives you a nice set of tick labels\r\n% with date strings. But often times, you may want to interact with your\r\n% plot by zooming and panning. Since |datetick| fixes the tick labels at\r\n% the time of creation, the labels may disappear if you zoom in too far or\r\n% pan away from the original limits. There are techniques you can employ to\r\n% automatically update the tick labels after \r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/ref\/zoom.html\r\n% zooming> and\r\n% <https:\/\/www.mathworks.com\/help\/releases\/R2010a\/techdoc\/ref\/pan.html\r\n% panning>, or you can use Ameya's |dynamicDateTicks|. \r\n%\r\n% Actually, there are a\r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/?term=tag%3A%22datetick%22\r\n% few entries> on the File Exchange that provide automatic update of\r\n% dateticks, one of which was selected as a\r\n% <https:\/\/blogs.mathworks.com\/pick\/2007\/07\/06\/adaptive-date-ticks\/ Pick of\r\n% the Week>. Most of them leverage the callback behaviors of zoom and pan.\r\n% What's unique about Ameya's function is that not only does it dynamically\r\n% update the tick labels as you zoom and pan, it also shows year or day\r\n% changes (so you always have the full date information), and displays data\r\n% tips appropriately.\r\n%\r\n% <<dynamicdateticks_screenshot.png>>\r\n%\r\n% *Comments*\r\n%\r\n% Give this a try and <https:\/\/blogs.mathworks.com\/pick\/?p=2549#respond tell\r\n% us> what you think, or leave a comment for Ameya on the  \r\n% <https:\/\/www.mathworks.com\/matlabcentral\/fileexchange\/27075-intelligent-dynamic-date-ticks\r\n% submission page>.\r\n##### SOURCE END ##### e5374933306c4607ab1631fdbcdc9658\r\n-->","protected":false},"excerpt":{"rendered":"<p>\r\n   Jiro's pick this week is Dynamic Date Ticks by our fellow MathWorker (and an Application Engineer) Ameya. If you work with time series data, this is a must-have utility.\r\n   \r\n   Have you ever... <a class=\"read-more\" href=\"https:\/\/blogs.mathworks.com\/pick\/2010\/04\/09\/dynamic-date-ticks\/\">read more >><\/a><\/p>","protected":false},"author":35,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[16],"tags":[],"_links":{"self":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2549"}],"collection":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/users\/35"}],"replies":[{"embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/comments?post=2549"}],"version-history":[{"count":0,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/posts\/2549\/revisions"}],"wp:attachment":[{"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/media?parent=2549"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/categories?post=2549"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blogs.mathworks.com\/pick\/wp-json\/wp\/v2\/tags?post=2549"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}