0
$\begingroup$

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"}}}
]
$\endgroup$
4
  • $\begingroup$ Which version are you using? $\endgroup$
    – Nasser
    Sep 8, 2013 at 12:42
  • $\begingroup$ I am using Mathematica 9.0 $\endgroup$
    – Jacccy
    Sep 8, 2013 at 12:59
  • 1
    $\begingroup$ 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. $\endgroup$
    – Kuba
    Sep 8, 2013 at 13:38
  • $\begingroup$ Oh man, thank you a lot!! $\endgroup$
    – Jacccy
    Sep 8, 2013 at 14:08

1 Answer 1

2
$\begingroup$

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

$\endgroup$
1
  • 1
    $\begingroup$ You can also use NumberForm as the second argument (second list position or w/e) instead of string. $\endgroup$
    – C. E.
    Sep 8, 2013 at 13:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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