1
$\begingroup$

Normally I can recover the options used on a DateListPlot easily with Options[]. However if one of the options said a Legend should be attached, it appears all the options are then unreadable.

For example, here are two plots identical apart from p2 has a legend. I can read the options for p1 fine, but Options on p2 returns nothing.

data1 = {{{2006, 10, 1}, 10}, {{2006, 10, 15}, 12}, {{2006, 10, 30}, 15}, {{2006, 11, 20}, 20}};
data2 = {{{2006, 10, 5}, 15}, {{2006, 10, 20}, 8}, {{2006, 11, 10}, 5}, {{2006, 11, 15}, 1}};
p1 = DateListPlot[{data1, data2}, Joined -> True]
p2 = DateListPlot[{data1, data2}, Joined -> True, PlotLegends -> Automatic]

Options[p1, FrameTicks]
Options[p2]

enter image description here

I am keen to be able to read the FrameTicks option to complete a function to create DateListPlots with 2 y-axis. Alexey Popkov kindly solved what I thought was my final problem, only for this one to appear from behind it:

Combine two DateListPlots and retain a time axis

$\endgroup$

1 Answer 1

1
$\begingroup$

This is because the structure of the graphics object returned by a plot with a legend is different. You need to look at the option of the first part of the returned object and you should be fine, i.e.

data1 = {{{2006, 10, 1}, 10}, {{2006, 10, 15}, 12}, {{2006, 10, 30}, 
    15}, {{2006, 11, 20}, 20}};
data2 = {{{2006, 10, 5}, 15}, {{2006, 10, 20}, 8}, {{2006, 11, 10}, 
    5}, {{2006, 11, 15}, 1}};
p1 = DateListPlot[{data1, data2}, Joined -> True];
p2 = DateListPlot[{data1, data2}, Joined -> True, 
  PlotLegends -> Automatic];

Options[p1, FrameTicks]
Options[p2[[1]]]


{FrameTicks -> {{Automatic, 
    Automatic}, {{{3368736000, "Oct 02"}, {3369945600, 
      "Oct 16"}, {3371155200, "Oct 30"}, {3372364800, 
      "Nov 13"}, {3373574400, "Nov 27"}, {3369340800, 
      ""}, {3370550400, ""}, {3371760000, ""}, {3372969600, 
      ""}}, {{3368736000, ""}, {3369945600, ""}, {3371155200, 
      ""}, {3372364800, ""}, {3373574400, ""}, {3369340800, 
      ""}, {3370550400, ""}, {3371760000, ""}, {3372969600, ""}}}}}

{FrameLabel -> {None, None}, AspectRatio -> 1/GoldenRatio, 
 AxesOrigin -> {3368649600, 0}, Frame -> True, 
 FrameTicks -> {{Automatic, 
    Automatic}, {{{3368736000, "Oct 02"}, {3369945600, 
      "Oct 16"}, {3371155200, "Oct 30"}, {3372364800, 
      "Nov 13"}, {3373574400, "Nov 27"}, {3369340800, 
      ""}, {3370550400, ""}, {3371760000, ""}, {3372969600, 
      ""}}, {{3368736000, ""}, {3369945600, ""}, {3371155200, 
      ""}, {3372364800, ""}, {3373574400, ""}, {3369340800, 
      ""}, {3370550400, ""}, {3371760000, ""}, {3372969600, ""}}}}, 
 GridLines -> {{{3368736000, GrayLevel[0.8]}, {3369945600, 
     GrayLevel[0.8]}, {3371155200, GrayLevel[0.8]}, {3372364800, 
     GrayLevel[0.8]}, {3373574400, GrayLevel[0.8]}}, None}, 
 Method -> {}, PlotRange -> {{3368649600, 3.37297*10^9}, {0, 20.}}, 
 PlotRangeClipping -> True, 
 PlotRangePadding -> {{86400., 86400.}, {0.4, 0.4}}, Ticks -> None}
$\endgroup$

Your Answer

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

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