Hubschr
Hubschr

Reputation: 1335

how can I put an arrow near my x/ylabel?

Im working with matplotlib and I want an arrow beside my "axis-legend". But I have no idea how. In the example, the arrows I want are drawn in red. example thanks

Upvotes: 10

Views: 11294

Answers (1)

Bonlenfum
Bonlenfum

Reputation: 20175

You can generate arrows as shown in your example figure by using the TeX renderer built into matplotlib. Coloring is an option for the whole strings, although generating multiple colors in a single text string is more work.

This will give you the mathematical symbols plus the arrows (I've shown different lengths on each axis label):

import matplotlib.pyplot as plt 
fig, ax = plt.subplots(1, 1)
# plot your data here ...

ax.set_xlabel(r'$\rho/\rho_{ref}\;\rightarrow$', color='red')
ax.set_ylabel(r'$\Delta \Theta / \omega \longrightarrow$')

plt.show()
plt.close()

Resulting in:

.

Partial coloring of text in matplotlib deals with multi-color strings, and this solution describes how to use the latex engine with multiple colors. However, it does not color what is rendered in the interactive graph, so it depends on your exact needs.

More arrows in LaTeX math mode

Upvotes: 16

Related Questions