Descargar el Código: patreon.com/pythonmaraton
Join Patreon: patreon.com/pythonmaraton
^Downloadable code & more! This video plots a lambda function and a list on the same plot using matplotlib pyplot as plt in python. This video shows you how to make a key or legend for the graph/plot. For more information on matplotlib watch some other videos I have made.
This is a Python anaconda tutorial for help with coding, programming, or computer science. These are short python videos dedicated to troubleshooting python problems and learning Python syntax. For more videos see Python Help playlist by Rylan Fowers.
✅Subscribe: / @pythonmaraton
📺Channel: / @pythonmaraton
▶️Watch Matplotlib Plotting tutorial: • Matplotlib Python Tutorial for Beginners
▶️ Watch Matplotlib Subplot tutorial: • Matplotlib Subplot Tutorial
▶️Watch Latest Python Content: • Python String Slice and List Slice
▶️Watch Latest Other Content: • Video
MATPLOTLIB LEGENDS
From matplotlib we import pyplot as plt
and numpy as np
For this example we will make a line and some data points and plot them together with a legend
So let’s make a domain, we will do a numpy linespace from 0 to 10 with 50 points
and let’s make a lambda function for our line 2x - 1
and now we will make a list with some data pints
data 1 will be our x values
and data2 we will create some y values that the line can estimate
now we will plot one at at time, first with the lambda function let’s make it a blue dashed line and we will include the keyword label and call it line, this will be important for our legend
Similarly we will plot the data points and let’s make those magenta diamond dots. And we will put the keyword label again, so we can use that in our legend. we will type “Points”
Now let’s just add a title and some axis labels really quick. ( you can see my matplotlib plotting video for more details on that)
and lastly we type plt.legend() and insert a list with our labels in place. so we will just type those out again for this example: Line and Points
Lastly let’s type plt.show() to see how this looks
Here is the plot. With the blue dashed line and the magenta diamond points. We have our labels of the x and y axis. and the Title we put. And there is our beautiful legend that we created. It automatically will put it in the most visible spot.
There you have it, that is how you make a legend for your python matplolib plots
#PythonMarathon #LearnPython #PythonTutorial
Auf dieser Seite können Sie das Online-Video Python Matplotlib Legend mit der Dauer stunde minuten sekunde in guter Qualität ansehen, das der Benutzer Python Marathon 11 August 2018 hochgeladen hat, den Link mit Freunden und Bekannten teilen, dieses Video wurde auf Youtube bereits 5,848 Mal angesehen und es wurde von 52 den Zuschauern gefallen. Viel Spaß beim Betrachtenden Zuschauern gefallen!