'How do I add an arrow head on a specific X value in Matplotlib? like shown in the figure below:

How to add an arrow-like shown in this figure which touches the X-axis at a specific value



Solution 1:[1]

You can use the .arrow() function.

import numpy as np
from matplotlib import cm, pyplot as plt
from matplotlib.axes import Axes
from matplotlib.figure import Figure

fig: Figure
ax: Axes
fig, ax = plt.subplots()

data = np.clip(np.random.randn(250, 250), -1, 1)
cax = ax.imshow(data, cmap=cm.coolwarm)
ax.arrow(
    150,
    -15,
    0,
    15,
    head_width=10,
    head_length=15,
    length_includes_head=True,
)

fig.show()

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 S P Sharan