3
$\begingroup$

Following this site, I inserted a LaTeX type set for the frame ticks. Following is the sample code.

Plot[
  Sin[x], {x, 0, \[Pi]}, 
  Frame -> True, FrameStyle -> Directive[Black],
  FrameTicks -> 
    {
     {{-1, -0.5, 0, -0, 0.5, 1}, None}, 
     {With[{ticks = Pi/4 Range[0, 4]}, Thread[{ticks, MaTeX[ticks, "DisplayStyle" -> False]}]], None}
    }, 
  Axes -> {False, False}, 
  PlotRange -> {{0.0, \[Pi]}, {-1, 1}},
  AxesLabel -> {x, "E"}, LabelStyle -> {GrayLevel[0]}
]

Below is the obtained plot:enter image description here

How to change the size of the x-axis frame tick labels and make them bold?

$\endgroup$
2
  • $\begingroup$ Why do you need LaTex for this? Just do FrameTicks -> {{Automatic, None}, {Range[0, Pi, Pi/4], None}} $\endgroup$ May 18, 2023 at 21:24
  • $\begingroup$ @rhomboidRhipper OP had question before on doing this using Mathematica without Latex. He must wanted now to do the same using Latex in Mathematica. $\endgroup$
    – Nasser
    May 18, 2023 at 22:38

1 Answer 1

5
$\begingroup$

How to change the size of the x-axis frame tick labels and make them bold?

Mathematica graphics

Code

<< MaTeX`
myNiceBigTicks = 
  With[{ticks = Pi/4 Range[0, 4]}, 
   {#, MaTeX["\\boldsymbol{" <> ToString@TeXForm[#] <> "}", 
       "DisplayStyle" -> False, Magnification -> 2]} & /@ ticks];

Plot[Sin[x], {x, 0, Pi},
 Frame -> True,
 FrameStyle -> Directive[Black],
 FrameTicks -> 
   {
     {{-1, -0.5, 0, -0, 0.5, 1}, None}, 
     {myNiceBigTicks, None}
   },
 Axes -> {False, False}, PlotRange -> {{0.0, Pi}, {-1, 1}}, 
 AxesLabel -> {x, "E"}, LabelStyle -> {GrayLevel[0]}
]

Is it also possible to bold the y-axis numbers together with x- axis?

The same thing can be done:

<< MaTeX`
myX = With[{ticks = 
     Pi/4 Range[0, 4]}, {#, 
      MaTeX["\\boldsymbol{" <> ToString@TeXForm[#] <> "}", 
       "DisplayStyle" -> False, Magnification -> 1.5]} & /@ ticks];
myY = With[{ticks = 
     Range[-1, 1, 1/2]}, {#, 
      MaTeX["\\boldsymbol{" <> ToString@TeXForm[#] <> "}", 
       "DisplayStyle" -> False, Magnification -> 1.5]} & /@ ticks];

Plot[Sin[x], {x, 0, Pi}, Frame -> True, 
 FrameStyle -> Directive[Black], GridLines -> Automatic, 
 GridLinesStyle -> LightGray, PlotStyle -> Red,
 FrameTicks -> {{myY, None}, {myX, None}}, Axes -> {False, False}, 
 PlotRange -> {{0.0, Pi}, {-1, 1}}, AxesLabel -> {x, "E"}, 
 LabelStyle -> {GrayLevel[0]}]

Mathematica graphics

Notice, this is not automated and need to manually give the range each time. Also Mathematica writes 1. as 1 for labels and 1/2 as 0.5. If you want the same you can add more code to do this. This is left as an exercise. The problem is that using Range[-1,1,.5] will produce {-1., -0.5, 0., 0.5, 1.} and not {-1, -0.5, 0, 0.5, 1} like mathematica does. So just need special formatting added, that is why I used Range[-1, 1, 1/2] instead.

$\endgroup$
5
  • $\begingroup$ Thanks! Is it also possible to bold the y-axis numbers together with x- axis? $\endgroup$
    – Rakesh
    May 19, 2023 at 0:49
  • $\begingroup$ @Rakesh fyi, updated. $\endgroup$
    – Nasser
    May 19, 2023 at 2:01
  • $\begingroup$ For the y-axis, I want to use Mathematica font. If I use "FrameTicksStyle -> Directive[Bold, 9, Black, Thickness[.003]]", it doesn't look uniform in color for both the x-axis and y-axis. Is there a way, to make y-axis numbers bold with mathematical font? $\endgroup$
    – Rakesh
    May 19, 2023 at 2:50
  • $\begingroup$ As mentioned above, if I use "FrameTicksStyle -> Directive[Bold, 9, Black, Thickness[.003]]", some tick lines become thick and some become slightly thicker. $\endgroup$
    – Rakesh
    May 19, 2023 at 2:52
  • $\begingroup$ @Rakesh it is not good idea to use Latex for one axis and Mathematica for another. They will not look same. MaTeX uses pdflatex to compile, and that uses the Computer Modern typeface family by default. You have to decide, either use Latex for ticks labels on everything, or use Mathematica's own typesetting. I think you asked in another question about using Mathematica for this. Anyway, I do not think I can help more I am afraid on this. good luck. $\endgroup$
    – Nasser
    May 19, 2023 at 4:56

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.