# How to plot mathematical expressions and symbols in vcs?¶

VCS can take advantage of matolotlib's text capabilites, this Jupyter notebook essentially shows how to implement in vcs the following matplolib tutorial

You can use a subset TeX markup in any vcs text string by placing it inside a pair of dollar signs ($). Note that you do not need to have TeX installed, since matplotlib ships its own TeX expression parser, layout engine and fonts. The layout engine is a fairly direct adaptation of the layout algorithms in Donald Knuth’s TeX, so the quality is quite good. Any text element can use math text. You should use raw strings (precede the quotes with an 'r'), and surround the math text with dollar signs ($), as in TeX. Regular text and mathtext can be interleaved within the same string. Mathtext can use DejaVu Sans (default), DejaVu Serif, the Computer Modern fonts (from (La)TeX), STIX fonts (with are designed to blend well with Times), or a Unicode font that you provide. The mathtext font can be selected with the customization variable mathtext.fontset see Customizing matplotlib

Simple example

In [1]:
import vcs
x=vcs.init(bg=True, geometry=(800,60))
# Convenience function for later in the script
def update():
x.clear()
return x.plot(text)

text = vcs.createtext()
# Position string
text.x = [.5]
text.y = [.5]
text.halign = "center"
text.valign = "half"
text.height = 250
text.string = "alpha > beta"
x.plot(text)

Out[1]:

produces “alpha > beta”.

Whereas this:

In [2]:
# mathematical text
text.string = r"$\alpha > \beta$"
update()

Out[2]:

Note

Mathtext should be placed between a pair of dollar signs (\$). To make it easy to display monetary values, e.g., “$100.00”, if a single dollar sign is present in the entire string, it will be displayed verbatim as a dollar sign. This is a small change from regular TeX, where the dollar sign in non-math text would have to be escaped (‘\$’). Note While the syntax inside the pair of dollar signs (\$) aims to be TeX-like, the text outside does not. In particular, characters such as:

x.plot(text2)
`
Out[15]: