Assume I have a function, that represents a path of a driving car:
import numpy as np
import matplotlib.pyplot as plt
# positions of the car
x = np.linspace(0, 20, 100)
y = np.sin(x)
fig, ax = plt.subplots(figsize=(12, 8))
ax.plot(x, y)
The car stops at certain positions and I want to mark these position in the graph by using the pause symbol, which some of you are certainly familiar with. The symbol is simply two vertical lines. Unfortunately, matplot does not have a marker that looks like that, however, matplot comes with the vertical line as a marker. So, as a plan B i came up with the following implementation:
# position where the car stops
x_stop = np.array([1, 5, 10])
y_stop = np.sin(x_stop)
# to create a stop symbol we shift the vertical line from matplot
shift = 0.1
ax.scatter(x_stop - shift, y_stop, marker='|', color='r', s=225, label='stop')
ax.scatter(x_stop + shift, y_stop, marker='|', color='r', s=225, label='stop')
plt.legend(loc='best')
The issue with this is that the legend obviously does not make sense. What I would like to have is the two markers next to each other in the legend, just like they appear in the graph on the path of the car. Is there a way to achieve this? Any other approach or a fix for my problem is fine!