Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

enter image description here

That has 3 disadvantage:

  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?

share|improve this question
    
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
1  
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
1  
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
show 3 more comments

3 Answers 3

up vote 1 down vote accepted

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:

PercentTicks example

The code is in my github repo.

share|improve this answer
    
Nice code. Tks. –  Murta Jul 11 at 2:18
add comment

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

plot

share|improve this answer
    
This theoretically works OK, but M version 8 has a bug and AbsoluteOptions doesn't work as expected for Ticks –  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 –  belisarius Jan 15 '13 at 16:26
    
It is v 8.0 BTW –  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
show 3 more comments

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

enter image description here

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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