# Percentage axis ticks

To create a percentage axe in some plot I use this Ticks configuration:

ListPlot[
Range[0,1,0.1]
,Ticks->{Automatic, {#,If[IntegerPart@Mod[100#,10]==0,Row[{100#,"%"}],""]}&/@Range[0,1,0.05]}
]


1. Non automatic range scale
2. No subticks with different sizes
3. It's nor elegant nor simple

I miss a Mathematica TicksFunction or equivalent, so I could have better control over it. I also tried something like: ListPlot[Quantity[Range[0, 1, 0.1], "Percent"]] without succes.

Some clue into a better approach?

-
Why not just relabelling the ticks ? – b.gatessucks Jan 15 '13 at 10:07
How can I do this? Using... – Murta Jan 15 '13 at 10:09
Define pc = {#, ToString[100 #] <> " %"} & /@ Range[0, 1, 0.1] and then Ticks -> {Automatic, pc}. – b.gatessucks Jan 15 '13 at 10:14
tks, but in this way you remove the subticks. – Murta Jan 15 '13 at 10:27
Would it fit to your approach to use the label, i.e. somethin like AxesLabel -> {"your x-axis label", "something in %"} and leave the TicksLabels as they are (and hence keep the MinorTicks ? – Ronny Jan 15 '13 at 10:36

In Mathematica 9, I developed a PercentTicks function to solve this problem. Here is an example of how it is used:

ListPlot[Table[{x, x}, {x, 0, .003, 0.0001}],
Ticks -> { Automatic, PercentTicks }]


which gives:

The code is in my github repo.

-
Nice code. Tks. – Murta Jul 11 '14 at 2:18

Replace the automatically generated labels to not have to care about generating the ticks yourself and preserve subticks:

percentTicks[plot_] := Module[{xticks, yticks},
{xticks, yticks} = (Ticks /. AbsoluteOptions[plot, Ticks]);
yticks =
yticks /. {y_, lbl_, rest__} /; lbl != "" :> {y, ToString[y*100] <> "%", rest};
Show[plot, Ticks -> {xticks, yticks}]
]

percentTicks@ListPlot[Sort@RandomReal[{0, 1}, {50}]]


-
This theoretically works OK, but M version 8 has a bug and AbsoluteOptions doesn't work as expected for Ticks – Dr. belisarius Jan 15 '13 at 15:21
@belisarius Got more details on that bug? I have v8 but can't break it. – ssch Jan 15 '13 at 16:22
Take a look at the x-axis ticks i.stack.imgur.com/T7kbm.png – Dr. belisarius Jan 15 '13 at 16:26
It is v 8.0 BTW – Dr. belisarius Jan 15 '13 at 16:26
It's not simple, but I agree it's the best that can be done with MMA until version 9. Tks! 1+ – Murta Jan 15 '13 at 19:53

You can take control of all relevant bits :

pcTicks = {#, ToString[100 #] <> " %", {0.02, 0}} & /@  Range[0, 1, 0.1];
pcSubTicks = {#, "", {0.01, 0}} & /@ (Range[0, 1, 0.1] + 0.05);

ListPlot[Range[0, 1, 0.1], Ticks -> {Automatic, Join[pcTicks, pcSubTicks]}]
`

-