4
$\begingroup$

I am making a ListPlot, in which the x-axis is the result of AbsoluteTime. I want the tick text to be human-readable by applying DateString, but don't want to mess with the automatic tick length. Is this possible? Thanks!

$\endgroup$
2
  • 2
    $\begingroup$ DateListPlot? $\endgroup$
    – Kuba
    Commented Mar 2, 2015 at 10:42
  • $\begingroup$ Don't know what you mean with tick length here, but if you're worried about the size of the label perhaps you could use Rotate? $\endgroup$ Commented Mar 2, 2015 at 11:49

1 Answer 1

7
$\begingroup$

Unless you specify the tick mark length in your tick specifications tick marks are rendered with default length and style.

tickF = {#, DateString[#, {"MonthNameShort", " ", "Day", "/", "YearShort"}]} & /@ 
  AbsoluteTime /@ DateRange[##, {10, "Day"}] &;

Example data:

data = {{3368649600, 8}, {3369427200, 10}, {3370291200, 12}, {3370636800, 14}, 
  {3371673600, 15}, {3372537600, 20}};

If you have to use ListPlot:

ListPlot[data, Frame -> True, Axes -> False, PlotRange -> Full,
 FrameTicks -> {tickF, Automatic, Automatic, Automatic}, 
 GridLines -> {First /@ tickF[##] &, None}]

enter image description here

If not, DateListPlot is more convenient to use for your data structure:

DateListPlot[data, PlotRange -> Full, 
  FrameTicks -> {tickF, Automatic, Automatic, Automatic}]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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