Ticks at multiples of $\pi$ in SciDraw

I'm having some trouble getting the labels right in a SciDraw figure. More precisely, I want labels at half-integer multiples of $\pi$, and I want them as clean inline fractions (i.e. as $\pi/2$ and not $\frac{\pi}{2}$. So far, what I've found works best is to get the numerator and denominator separately and then join them as strings,giving something like

Plot[  Cos[ωt]^2  , {ωt, -0.3, 2 π + 0.3}  , Frame -> True  , FrameTicks -> {{None, None}, {     Function[{#,        Style[         StringReplace[          ToString[Numerator[Rationalize[#/π]]] <> "π/" <>            ToString[Denominator[Rationalize[#/π]]]          , {"/1" -> "", "1π" -> "π", "0π" -> "0"}]         , FontSize -> 30         ]        }] /@ Range[0, 2 π, π/2]     , None}}  ] 

Ticks at multiples of $\pi$ in SciDraw

If I do this in SciDraw, though, using the XTicks and LinTicks specifications,

Figure[  FigurePanel[{    FigGraphics[      Plot[Cos[ωt]^2, {ωt, -0.3, 2 π + 0.3}]      ];    }   , XPlotRange -> {-0.3, 2 π + 0.3}   , XTicks -> LinTicks[-2 π, 2 π, π/2, 1, TickLabelFunction ->      Function[       Style[        StringReplace[         ToString[Numerator[Rationalize[#/π]]] <> "π/" <>            ToString[Denominator[Rationalize[#/π]]]         , {"/1" -> "", "1π" -> "π", "0π" -> "0"}]        , FontSize -> 30        ]       ]     ]   ]  , CanvasSize -> {5, 3}  ] 

the output doesn't quite look right:

Ticks at multiples of $\pi$ in SciDraw

In particular, note the incorrect positioning of the label at $\pi$. \[SadSmiley]. So:

  • Is there a way to get SciDraw to place these ticks correctly?
  • (Why is it doing it anyway?)
  • Am I barking up the wrong tree with these string replacements, i.e. is there a simpler way to produce this output?

Replay

Try setting TextPadding -> True. It does more or less the same as the builtin ContentPadding. It is described in SciDrawGuide.pdf.



What ContentPadding -> True does, in simple terms, is that it makes the enclosing box have a vertical size equal to a full line height. Otherwise the box has the same height as the enclosed character/text. SciDraw positions textual elements wrapped in boxes. For good alignment it is necessary that all boxes have the same height. This is done by enforcing a minimum line height. MaTeX also has such an option, precisely for dealing with this kind of problem.



Example:

<< SciDraw`

labelFun[x_, _] :=
  Module[{frac = Rationalize[x/Pi] Pi, num, den},
    num = Numerator[frac];
    den = Denominator[frac];
    If[den == 1,
      num,
      StringForm["``/``", num, den]
    ]
  ]

Figure[
 FigurePanel[{[email protected][Cos[ωt]^2, {ωt, 0, 2 π}];},
  XPlotRange -> {0, 2 π},
  XTicks -> LinTicks[-2 Pi, 2 Pi, Pi/2, 4, TickLabelFunction -> labelFun],
  TextPadding -> True,
  XExtendRange -> 0.02, YExtendRange -> 0.04
  ],
 CanvasSize -> {5, 3}]

I'm not sure what the best way is to get correct spacing around the / sign, but the following works: replace the string in StringForm with "\!\(TraditionalForm\```/``\)". This is a string representation of boxes. I obtained it by writing a single character into a string, selecting it, then pressing Command-Shift-T to convert it to TraditionalForm. This created a traditional form environment within the string. Then I deleted the character and typed what I wanted instead.

Ticks at multiples of $\pi$ in SciDraw

To set things such as font size, etc. use options such as FontSize, TickFontSize, XTickFontSize, etc., depending on how specific you want to be. It is not necessary to use Style here. These can also be set at the level of the Figure, as these options are inherited. Or you can use DefineStyle and re-use it across several figures. That's what I usually do when using SciDraw.

You may also be interested in the *TextNudge options, e.g. try XTickTextNudge -> -2 to position the ticks further from the frame. I tend to find the SciDraw default too tight.

Category: plotting Time: 2016-07-28 Views: 0

Related post

iOS development

Android development

Python development

JAVA development

Development language

PHP development

Ruby development

search

Front-end development

Database

development tools

Open Platform

Javascript development

.NET development

cloud computing

server

Copyright (C) avrocks.com, All Rights Reserved.

processed in 0.175 (s). 12 q(s)