Search code examples
pythonmatplotlibmatrixvectorlatex

How to write out a column vector


How do I add a column vector as text to my plot using matplotlib?

For example:

enter image description here

Is there a way of writing this using plt.text()? The closest I've got is writing it out as a fraction, although not encapsulated by brackets:

plt.text(0,0, r'$\frac{x}{y}$')

However, as it's a vector, I effectively need a line-less fraction contained within brackets.


Solution

  • If you only need a 2-vector, you can use the \binom{}{} LaTeX command.

    import matplotlib.pyplot as plt
    
    plt.text(0, 0, r"$\binom{x}{y}$", fontsize=100, ha="center", va="center")
    plt.xlim(-1,1)
    plt.ylim(-1,1)