0
$\begingroup$

How can I control the number of decimal places the ticks show along the horizontal and vertical axes? I have tried various approaches but ListLinePlot seems to automate it.

     r=2;NN=10;y0=0.1;
sol = RecurrenceTable[{y[k + 1] == r*y[k]*(1 - y[k]), y[0] == y0}, y, {k, 0, NN}]; AA = ListLinePlot[sol, Mesh -> All, AxesOrigin -> {-1, 0},  DataRange -> {0, NN} , 
PlotStyle -> {{Thickness[0.0015], Blue}, PointSize[0.021]}];
BB = Plot[(r - 1)/r, {x, 0, NN}, PlotStyle -> {{Thickness[0.0025], Red}}];
Show[AA, BB, Ticks -> {Range[0, NN, 1], Range[0, 1, 0.05]}]
$\endgroup$
2

2 Answers 2

1
$\begingroup$

To control the number of decimal places displayed on the horizontal and vertical axes in a ListLinePlot or any other plot in Mathematica, you can use the NumberForm function within the Ticks option. Here's how you can modify your existing code to control the number of decimal places for the tick labels:


r = 2; NN = 10; y0 = 0.1;

sol = RecurrenceTable[{y[k + 1] == r*y[k]*(1 - y[k]), y[0] == y0}, 
   y, {k, 0, NN}];

AA = ListLinePlot[sol, Mesh -> All, AxesOrigin -> {-1, 0}, 
   DataRange -> {0, NN}, 
   PlotStyle -> {{Thickness[0.0015], Blue}, PointSize[0.021]}, 
   Ticks -> {Automatic, 
     Table[{i, NumberForm[i, {2, 1}]}, {i, 0, 1, 0.05}]}];

BB = Plot[(r - 1)/r, {x, 0, NN}, 
   PlotStyle -> {{Thickness[0.0025], Red}}];

Show[AA, BB, Ticks -> {Range[0, NN, 1], Range[0, 1, 0.05]}]
$\endgroup$
1
  • 1
    $\begingroup$ wonderful ... many thanks Athanasios! $\endgroup$
    – user42700
    Sep 5, 2023 at 13:18
1
$\begingroup$

Use pairs of values and print formats eg

ListLinePlot[Array[({#*\[Pi]/77.2, 12 E^(1/#)} &), {22}], 
Ticks -> 
 {({#, Style[ScientificForm[ #, 3], 6]} &) /@  Range[0, 1,  0.3389076], 
  ({#, Style[AccountingForm[ #, {4, 2}], 4]} &) /@ Range[10, 20, 0.987654321]}]

Ticks formatting

$\endgroup$
1
  • $\begingroup$ How to apply this to my code? $\endgroup$
    – user42700
    Sep 5, 2023 at 10:43

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.