I came across some unexpected inconsistencies when further developing the solution to an earlier question:
How can I show % values on the y axis of a plot?
This seemed different enough to merit a new post.
Starting with the same data:
data = {{{2010, 8, 3},
0.}, {{2010, 8, 31}, -0.052208}, {{2010, 9, 30},
0.008221}, {{2010, 10, 29}, 0.133203}, {{2010, 11, 30},
0.044557}, {{2010, 12, 31}, 0.164891}, {{2011, 1, 31},
0.055141}, {{2011, 2, 28}, 0.114801}, {{2011, 3, 31},
0.170501}, {{2011, 4, 29}, 0.347566}, {{2011, 5, 31},
0.461358}, {{2011, 6, 30}, 0.244649}, {{2011, 7, 29},
0.41939}, {{2011, 8, 31}, 0.589874}, {{2011, 9, 30},
0.444151}, {{2011, 10, 31}, 0.549095}, {{2011, 11, 30},
0.539669}};
I defined a way to make FrameTicks
with percentages built on the contributions and insights offered in the last post:
myFrameTicks =
Table[
{k/10., ToString@(10 k) <> "%"},
{
k,
IntegerPart[Floor[Min@data[[All, 2]], .1]*10],
IntegerPart[Ceiling[Max@data[[All, 2]], .1]*10]
}
];
Now look at two plots of the same data using the same FrameTicks
:
DateListPlot[data, FrameTicks -> {{myFrameTicks, None}, {Automatic, None}}]
ListPlot[data[[All, 2]], FrameTicks -> {{myFrameTicks, None}, {Automatic, None}}]
So, why don't both of these plots show the frame ticks as percentage (e.g., 60%) like the first one does?
I might have missed something obvious (not the first time). Also, this approach doesn't appear to work when used with ListLinePlot
or BarChart
, both of which seem to accept a FrameTicks
attribute.
DateListPlot
defaults to Frame->True
. ListPlot
defaults to Frame->False
. It is displaying Ticks, not FrameTicks.
Try setting the Frame
to true:
DateListPlot[data,
FrameTicks -> {{myFrameTicks, None}, {Automatic, None}}]
ListPlot[data[[All, 2]],
Frame -> True,
FrameTicks -> {{myFrameTicks, None}, {Automatic, None}}]