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.

I have following problem:

I want to set the values for the X-and Y axis by myself, but the values (e.g. 0.800) are not plotted as I defined them (see image 0,8), mathematica removes the zeros.

Data = {{58.771, 0.792}, {53.532, 0.801}, {48.083, 0.795}, {57.343,0.794524}};
AxisY = {0.795, 0.800};
AxisX = {48, 53, 58};
ShowLegend[ 
  Show[
    {ListPlot[Data]},
    Frame -> {True, True, False, False},
    FrameTicks -> {{AxisY, Automatic}, {AxisX, Automatic}}
  ],
  {{{Graphics[{Blue, Disk[{0, 0}, 1]}], "ABC"}}}
]

enter image description here

I tried to solve this problem with NumberForm, but that does't work, the Y-axis disappears. SetPrecision doesn't work in my case, because I don't want to set total positions, I want to set positions after decimal point. Have someone an idea to solve this problem with an easy way?

ShowLegend[ 
  Show[
    {ListPlot[Data]},
    Frame -> {True, True, False, False},
    FrameTicks -> {{NumberForm[#, {4, 2}] &@{Axisy}, Automatic}, {Axisx,Automatic}}
  ],
  {{{Graphics[{Blue, Disk[{0, 0}, 1]}], "ABC"}}}
]
share|improve this question
    
Which version are you using? –  Nasser Sep 8 '13 at 12:42
    
I am using Mathematica 9.0 –  Jacccy Sep 8 '13 at 12:59
1  
Your way will not work because NumberForm is not a Number. But if you take a closer look at Details & Options for Ticks you will see that the fast fix would be to put there {#, NumberForm[#, {4, 3}]} & /@ AxisY. –  Kuba Sep 8 '13 at 13:38
    
Oh man, thank you a lot!! –  Jacccy Sep 8 '13 at 14:08

1 Answer 1

You can force these ticks as follows

Needs["PlotLegends`"];
ticksy[min_, max_] := {{0.795, "0.795"}, {0.800, "0.800"}};
ticksx[min_, max_] := {{48, "48"}, {53, "53"}, {58, "58"}};
Data = {{58.771, 0.792}, {53.532, 0.801}, {48.083, 0.795}, {57.343,0.794524}};
ShowLegend[Show[{ListPlot[Data]}, Frame -> {True, True, False, False}, 
  FrameTicks -> {{ticksy, Automatic}, {ticksx, 
     Automatic}}], {{{Graphics[{Blue, Disk[{0, 0}, 1]}], "ABC"}}}]

Mathematica graphics

or can use a formatting function instead of string like this

Needs["PlotLegends`"];
padIt2[v_, f_] := AccountingForm[v, f, NumberSigns -> {"", ""}, 
   NumberPadding -> {"0", "0"}, SignPadding -> True];
ticksy[min_, max_] := Table[{i, padIt2[i, {5, 4}]}, {i, min, max, .001}];
ticksx[min_, max_] := {#, padIt2[#, 2]} & /@ {48, 53, 58};
Data = {{58.771, 0.792}, {53.532, 0.801}, {48.083, 0.795}, {57.343, 0.794524}};

ShowLegend[
 Show[{ListPlot[Data]}, Frame -> {True, True, False, False}, 
  FrameTicks -> {{ticksy, Automatic}, {ticksx, 
     Automatic}}], {{{Graphics[{Blue, Disk[{0, 0}, 1]}], "ABC"}}}]

Mathematica graphics

share|improve this answer
1  
You can also use NumberForm as the second argument (second list position or w/e) instead of string. –  Pickett Sep 8 '13 at 13:00

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.