Think about doing this:
import matplotlib.pyplot as plt
plt.plot(x_A,y_A,'g--')
plt.plot(x_B,y_B,'r-o')
plt.show()
How would you go about giving both lines different names, i.e. like Microsoft Excel would do it?
You can plot multiple lines from the data provided by an array in python using matplotlib. You can do it by specifying different columns of the array as the x and y-axis parameters in the matplotlib. pyplot. plot() function.
Multiple Legends. Sometimes when designing a plot you'd like to add multiple legends to the same axes. Unfortunately, Matplotlib does not make this easy: via the standard legend interface, it is only possible to create a single legend for the entire plot. If you try to create a second legend using plt.
import matplotlib.pyplot as plt
plt.plot(x_A,y_A,'g--', label="plot A")
plt.plot(x_B,y_B,'r-o', label="plot A")
plt.legend()
plt.show()
You can give each line a label.
plt.plot(x_A,y_A,'g--', label='x_A')
These labels can then be displayed in a legend with
legend()
legend
takes some arguments, see the documentation to see what it can do.
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