Search code examples
pythonmatplotlibplot

Down arrow symbol in matplotlib


I would like to create a plot where some of the points have a downward pointing arrow (see image below). In Astronomy this illustrates that the true value is actually lower than what's measured.Note that only some of the points have this symbol.

I would like to know how I can create such symbols in matplotlib. Are there downward arrow symbols that I can use?

Thanks for your help in advance!

enter image description here


Solution

  • Sure.

    When calling matplotlibs plot function, set a marker

    • If stuff like caretdown doesn't work for you, you can create your own marker by passing a list of (x,y) pairs, which are passed to a Path artist. x/y are 0…1 normalized coordinates that are scaled to the set marker size.
    • You can also pass an existing Path instance as a marker, which allows even more flexibility.
    • As mentioned by tom10 in the comments you can also pass a string in the form of $…$ as a marker, where is arbitrary text, including Unicode characters, if your font supports it (should be the case these days). Downwards arrow in Unicode: ↓ (or \u2193, resulting in $\u2193$ as the marker. Note that this must be a unicode string in Python 2.x [prepend u]). Unicode Block Arrows @ Wikipedia
    • You could also try passing a Arrow instance as marker, but I'm not sure whether that works.