3

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}}]

Mathematica graphics

ListPlot[data[[All, 2]], FrameTicks -> {{myFrameTicks, None}, {Automatic, None}}]

Mathematica graphics

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.

Community
  • 1
  • 1
Jagra
  • 3,149
  • 1
  • 18
  • 19
  • I did mention this in my (accepted, thank you) answer toyour question :-). Maybe I should have stressed it more. – Timo Dec 03 '11 at 20:56

2 Answers2

7

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}}]
Brett Champion
  • 8,497
  • 1
  • 27
  • 44
DavidC
  • 3,056
  • 1
  • 20
  • 30
2

We have FrameTicks for Frame, and Ticks for Axes, so in addition to David's solution of turning on the frame for ListPlot, you could instead specify your function for Ticks:

ListPlot[data[[All, 2]], Ticks -> {Automatic, myFrameTicks}]

(Note the difference in ordering.)

Brett Champion
  • 8,497
  • 1
  • 27
  • 44