0
$\begingroup$

I'm currently working on generating several function plots and have been using the following code as a template:

<< MaTeX`
Plot[Sin[x], {x, -2, 2}, Frame -> True, 
 FrameTicks -> {{(*y-axis*)
    Table[{x, 
      MaTeX[x, "DisplayStyle" -> False, Magnification -> 1.1]}, {x, 
      0.1 Range[-10, 10]}], 
    Table[{x, 
      MaTeX["", "DisplayStyle" -> False, Magnification -> 0.2]}, {x, 
      0.1 Range[-10, 10]}]}, {(*x-axis*)
    Table[{x, 
      MaTeX[x, "DisplayStyle" -> False, Magnification -> 1.2]}, {x, 
      0.2 Range[-10, 10]}], 
    Table[{x, 
      MaTeX["", "DisplayStyle" -> False, Magnification -> 0.001]}, {x,
       0.2 Range[-10, 10]}]}}]

However, I've noticed that each plot requires customizing the vertical ticks. I'm wondering if there's an option available to automatically assign vertical ticks while preserving the LaTeX format.

Thank you.

$\endgroup$

2 Answers 2

1
$\begingroup$

You could use

Plot[Sin[x], {x, -2, 2}, Frame -> True, ImagePadding -> 20]

Mathematica graphics

Replace with

myYtick[min_, max_] := 
  Table[If[
    Mod[i, 0.5] == 0, {i, MaTeX[Rationalize[i]], {.03, 0.0}, 
     Black}, {i, Null, {0.01, 0.0}}], {i, Ceiling[min], 
    Floor[max], .1}];
myXtick[min_, max_] := 
  Table[If[
    Mod[i, 1] == 0, {i, MaTeX[Rationalize[i]], {.03, 0.0}, Black}, {i,
      Null, {0.01, 0.0}}], {i, Ceiling[min], Floor[max], .1}];

Plot[Sin[x], {x, -2, 2}, 
 FrameTicks -> {{myYtick, Automatic}, {myXtick, Automatic}}, 
 Frame -> True]

Mathematica graphics

If you do not want fractions, but decimals like Mathematica shows, then simply change MaTeX[Rationalize[i]] with MaTeX[i] and the output now looks like

Mathematica graphics

If you want the minor tick to be shorter, change {i, MaTeX[i], {.03, 0.0}, Black} to {i, MaTeX[i], {.02, 0.0}, Black}

$\endgroup$
0
$\begingroup$

I think I fund one asnwer:

<< MaTeX`
Plot[Sin[x], {x, -2, 2}, Frame -> True,
 FrameTicks -> {
   {Map[{#, MaTeX[#, "DisplayStyle" -> False, "Magnification" -> 1.1]} &, FindDivisions[{-2, 2}, 8]], 
    Map[{#, MaTeX[#, "DisplayStyle" -> False, "Magnification" -> 0.2]} &, FindDivisions[{-2, 2}, 24]]},
   {Map[{#, MaTeX[#, "DisplayStyle" -> False, "Magnification" -> 1.2]} &, FindDivisions[{-1, 1}, 5]], 
    Map[{#, MaTeX[#, "DisplayStyle" -> False, "Magnification" -> 0.001]} &, FindDivisions[{-1, 1}, 10]]}
 }
]

In this code, one adjust the parameters between the Max and Min of the function.

$\endgroup$

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.