Uniform Spacing With Matplotlib And Tex
I am drawing up some graphs for a math class, and I can't get the spacing for peacewise definitions quite right in the plot legend. I am currently using \, for a single space in T
Solution 1:
You can certainly improve on the spacing by accessing a lower level of LaTeX. To begin, at the top of your plots run:
from matplotlib import rc
rc('text', usetex=True)
Using a combination of \makebox
and \hfill
you can pad out the spaces between the two sections:
label=r"\makebox[4cm]{$t^2$ \hfill $0 \leq t \leq 1$}"
label=r"\makebox[4cm]{$1$ \hfill $1 < t \leq 2$}"
label=r"\makebox[4cm]{$3 - t$ \hfill $2 < t \leq 3$}"
Admittedly this isn't perfect, but with a combination of multiple \makebox
and fills you can fine tune what you need. Ideally, you could write a custom legend handler that is "aware" of a multi-line block of TeX, but I'm sure this is non-trivial.
Post a Comment for "Uniform Spacing With Matplotlib And Tex"