1
$\begingroup$

I tried to rotate my TickLabels with another contribution from this website.

I load the package CustomTicks.m

Beta0 = Import["beta0_Monatsende.xls"];
DateListPlot[Beta0, PlotRange -> Full; 
FrameLabel -> {Zeit [Monat], Subscript[\[Beta], 0]}, 
FrameTicks -> {{LinTicks[0, 14, 2, 2], 
 LinTicks[0, 14, 2, 
  2]}, {{{1972, 09}, {1975, 09}, {1978, 09}, {1981, 09}, {1984, 
   09}, {1987, 09}}, Automatic}}, 
DateTicksFormat -> {"MonthNameShort", " ", "Year"}] /.x : (FrameTicks -> _) :> (x /. s_String :> Rotate[s, 90 Degree])

Now the labels on the x axis are rotated, but also on the y axis. Is there any possibility to rotate only the labels on the x axis?

enter image description here

$\endgroup$
7
  • 1
    $\begingroup$ Where did LinTicks[] come from? $\endgroup$ – J. M.'s torpor Oct 10 '18 at 10:26
  • $\begingroup$ I load the package CustomTicks.m $\endgroup$ – Sarah Oct 10 '18 at 10:27
  • $\begingroup$ Yes, please mention if you have loaded any packages that are not built-in in your question the next time. $\endgroup$ – J. M.'s torpor Oct 10 '18 at 10:29
  • 1
    $\begingroup$ After the /. in the snippet you gave, try this replacement rule instead: x : (FrameTicks -> _) :> MapAt[# /. s_String :> Rotate[s, π/2] &, x, {2, 2, 1}] $\endgroup$ – J. M.'s torpor Oct 10 '18 at 10:39
  • 1
    $\begingroup$ (If anyone else wants to write it up as an answer, please do so; my gedanken Mathematica does not allow for producing plots.) $\endgroup$ – J. M.'s torpor Oct 10 '18 at 10:48
2
$\begingroup$

You can use a custom ticks function:

rotatedDateTicksF[n_]:= MapAt[Rotate[#, Pi/2] &, System`DateListPlotDump`DateTicks[{##}, 
   n, {"MonthNameShort", " ", "Year"}], {All, 2}] &;

Examples:

data = Accumulate[RandomReal[{-1, 2}, 20]];
DateListPlot[data, {{2015, 1, 1}, Automatic, "Month"}, 
  FrameTicks -> {{Automatic, Automatic}, {rotatedDateTicksF[5], Automatic}}, 
  FrameLabel -> {Zeit[Monat], Subscript[β, 0]}, 
  DateTicksFormat -> {"MonthNameShort", " ", "Year"}]

enter image description here

Change rotatedDateTicksF[5] to rotatedDateTicksF[10] to get

enter image description here

$\endgroup$
3
  • $\begingroup$ I tried it with version 12.0.0.0. It did not worked (anymore?): "A ticks specification in the value of FrameTicks should be None, Automatic, a function, or a list of ticks" $\endgroup$ – M.A. Jan 31 '20 at 10:54
  • $\begingroup$ or does it not work because I need the package above?? $\endgroup$ – M.A. Jan 31 '20 at 11:09
  • 1
    $\begingroup$ @M.A., I don't understand why it doesn't work in v12.0. A work-around is to use rotatedDateTicksF[5][{2015, 1, 1}, DatePlus[{2015, 1, 1}, {20, "Month"}]] instead of rotatedDateTicksF[5] (You don't need the CustomTicks package for this) $\endgroup$ – kglr Jan 31 '20 at 11:23

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.