0
$\begingroup$

I have a problem in plotting a function. The example code is as following:

d = 0.1;
M[x_] := ((x/d) - 0.4);
Plot[p[x], {x, 0, 10}, Ticks -> {{0, d, 2d, 3d}, {1, 1}}] 

I would like to have $d,\ 2d,\ 3d$ and so on the x-axis label at right positions, i.e. at $0.1,\ 0.2$ and so on. How can I achieve this?

$\endgroup$
0
4
$\begingroup$

You mean something like this? (ps. I assume your M[x_] is meant to be p[x]

 tick[min_, max_] := 
  Table[{i, Row[{Rationalize[i/d], "d"}], {.01, 0}, Black}, {i, 
    Ceiling[min], Floor[max], 10*d}];
d = 0.1;
maxRange = 10;
p[x_] := ((x/d) - 0.4);
Plot[p[x], {x, 0, maxRange}, Frame -> True, 
 FrameTicks -> {{Automatic, None}, {tick, None}}, 
 GridLines -> {Range[0, 10], Automatic}, GridLinesStyle -> LightGray]

enter image description here

You can play with the tick styling as you want, change the number formatting, etc...

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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