Search code examples
pythonmatplotlibscatter-plot

How do I get backslash marker in matplotlib?


I was hoping for this Python 3.11 script to render \ markers:

import numpy as np, matplotlib.pyplot as plt

plt.scatter([1, 2, 3], [3, 1, 4], marker='$\textbackslash$', c='b')
plt.show()

but it renders - instead. How do I get \ or similar marker?


Solution

  • This link provides all the supported mathtext symbols you can use:

    https://matplotlib.org/stable/users/explain/text/mathtext.html

    For a backslash try marker=r'$\backslash$'