Down arrow symbol in matplotlib
Rise to the top 3% as a developer or hire one of them at Toptal: https://topt.al/25cXVn
--------------------------------------------------
Music by Eric Matyas
https://www.soundimage.org
Track title: Riding Sky Waves v001
--
Chapters
00:00 Down Arrow Symbol In Matplotlib
00:30 Accepted Answer Score 11
01:25 Answer 2 Score 3
02:08 Answer 3 Score 3
02:22 Answer 4 Score 6
02:53 Thank you
--
Full question
https://stackoverflow.com/questions/1686...
--
Content licensed under CC BY-SA
https://meta.stackexchange.com/help/lice...
--
Tags
#python #matplotlib #plot
#avk47
ACCEPTED ANSWER
Score 11
Sure.
When calling matplotlibs plot function, set a marker
- If stuff like
caretdowndoesn'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
Pathinstance as amarker, 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
Arrowinstance as marker, but I'm not sure whether that works.
ANSWER 2
Score 6
Matplotlib supports a subset of Latex in a built-in module called mathtext. The main purpose is to properly render mathematical and scientific equations and symbols, but there's also large number of arrow symbols that can easily be used in your graphs. The following link is to the tutorial for writing math expressions. Near the bottom of the page is a list of about 80 arrow symbols.
https://matplotlib.org/stable/users/explain/text/mathtext.html
Examples:
plt.plot(x, y, marker=r'$\uparrow$')
plt.plot(x, y, marker=r'$\downarrow$')
ANSWER 3
Score 3
The answer to my question was answered by Tom0 and Dom0. However, I just want to help the newbies like me understand how to plot those arrows. Below is the code that I found and edited to include what is said in the above example and suggestion. I hope this will help people quickly understand. I am not seeking any points.
If you like the example, please thank Dom0 and not me. :-)
import numpy as np
import matplotlib.pyplot as plt
symbols = [u'\u2193'] # this helps you get the symbol
x = np.arange(10.)
y = np.exp(-x/2.)
plt.figure()
for i, symbol in enumerate(symbols):
y2 = np.exp(-x/2.)
plt.plot(x, y, 'o') # plotting with field circles
plt.plot(x, y2, 'g') # plotting with green line
for x0, y0 in zip(x, y2):
plt.text(x0, y0, symbol, fontname='STIXGeneral', size=30, va='center', ha='center', clip_on=True)
plt.show()
ANSWER 4
Score 3
Take a look at this example code: http://matplotlib.org/examples/pylab_examples/errorbar_limits.html
OR: Another easy way to do this:
arrow = u'$\u2193$'
ax.plot(x, y, linestyle='none', marker=arrow, markersize=10)