How can I show % values on the y axis of a plot?
Asked Answered
P

4

7

In any Mathematica chart or plot how can I show % values on the y axis?

I may have data like this:

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

DateListPlot@data

I just want the y axis to range from 0% to 60% instead of 0.0 to 0.6.

Pare answered 2/12, 2011 at 16:19 Comment(0)
D
8

Use FrameTicks -> {{left, right},{bottom, up}}

DateListPlot[data, 
             FrameTicks -> {{{{0.0, "0%"}, {0.1, "10%"}, {0.2, "20%"}, 
                              {0.3, "30%"}, {0.4, "40%"}, {0.5, "50%"}, 
                              {0.6, "60%"}}, None}, 
                            {Automatic, None}}]

enter image description here

The table for FrameTicks can be generated, e.g.,

Table[{k/10., ToString@(10 k) <> "%"}, {k, 6}]
(* Out[10] := {{0.1, "10%"}, {0.2, "20%"}, {0.3, "30%"}, {0.4, "40%"}, {0.5, "50%"}, {0.6, "60%"}} *)

If you need to make a lot of figures there is LevelScheme, a free package that makes producing good plots in Mathematica much easier, especially when it comes to tick marks.

EDIT: As per Jagra's suggestion here is a function that makes a tick specification list based on the data set and with desired tick steps. Assumptions are that the data structure is the always the same.

ticks[step_, data_] := {{Table[{k, ToString@IntegerPart@(100 k) <> "%"}, 
                               {k, 
                                Floor[Min@data[[All, 2]], step],
                                Ceiling[Max@data[[All, 2]], step], 
                                step}], None}, 
                         {Automatic, None}}; 

Now you can define a plotting function

plot = DateListPlot[#, FrameTicks -> ticks[.1, #]] &

and use it like this plot@data

Finally, since your question specifies any Mathematica plot, remember that FrameTicks works only on framed plots, for other plots use Ticks -> {{x ticks},{y ticks}}.

Duckling answered 2/12, 2011 at 17:27 Comment(1)
I tried the following to more automate the solution, given I won't know the plots range before hand. One could probably simplify it further: DateListPlot[data, FrameTicks -> {{Table[{k/10., ToString@(10 k) <> "%"}, {k, IntegerPart[Floor[Min@data[[All, 2]], .1]*10], IntegerPart[Ceiling[Max@data[[All, 2]], .1]*10] }], None}, {Automatic, None}}]Pare
C
6

You could try fiddling with FrameTicks:

enter image description here

Chapen answered 2/12, 2011 at 17:24 Comment(0)
K
5

Assuming your y-axis values are given as ratios and you want them as percentages, the simplest solution is:

DateListPlot[{#1, 100 #2} & @@@ data]

enter image description here

Kanter answered 2/12, 2011 at 17:17 Comment(0)
A
-1

I do not see the graphics options, such a possibility, but you can create an intermediate function that will convert your number to the right. You're going to display the graph of this function. This can be done easily. Good luck!

Altercation answered 2/12, 2011 at 16:38 Comment(1)
I'm sorry to say but this answer, apart from being vague and almost devoid of information, is also dead wrong.Klapp

© 2022 - 2024 — McMap. All rights reserved.