I followed the documentation but still failed to label a line.
plt.plot([min(np.array(positions)[:,0]), max(np.array(positions)[:,0])], [0,0], color='k', label='East') # West-East
plt.plot([0,0], [min(np.array(positions)[:,1]), max(np.array(positions)[:,1])], color='k', label='North') # South-North
In the code snippet above, I am trying to plot out the North direction and the East direction.
position
contains the points to be plotted.
But I end up with 2 straight lines with NO labels as follows:
Where went wrong?
To plot a line plot in Matplotlib, you use the generic plot() function from the PyPlot instance. There's no specific lineplot() function - the generic one automatically plots using lines or markers. This results in much the same line plot as before, as the values of x are inferred.
The argument label
is used to set the string that will be shown in the legend. For example consider the following snippet:
import matplotlib.pyplot as plt
plt.plot([1,2,3],'r-',label='Sample Label Red')
plt.plot([0.5,2,3.5],'b-',label='Sample Label Blue')
plt.legend()
plt.show()
This will plot 2 lines as shown:
The arrow function supports labels. Do check this link: http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.arrow
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With