add legends to y plots matplotlib 1

add legends to y plots matplotlib

plt.plot(xs, y_1s, "-b", label="x^2")

plt.plot(xs, y_2s, "-g", label = "2x + 1")


plt.legend()


Here is what the above code is Doing:
1. We’re creating a list of x values from 0 to 10, in increments of 0.1.
2. We’re creating a list of y values for the function x^2.
3. We’re creating a list of y values for the function 2x + 1.
4. We’re plotting the x and y values for the function x^2.
5. We’re plotting the x and y values for the function 2x + 1.
6. We’re adding a legend to the plot.

Similar Posts