filmov
tv
Matplotlib Subplot Tutorial
Показать описание
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.
MATPLOTLIB SUBPLOTS
We open ipython and begin by importing py plot from matplotlib and numpy as np so we can use some of it’s functions
In this example we will be making four subplots. So we will name the first one first and define it as a subplot 221. This means it is a 2 by 2 set of subplots and this first one is in position 1
We will set some labels on our subplot. Type first dot then the set underscore title. You can do the same for x and y labels. lastly, to make this more clean, we will get rid of the tick marks for our subplot by doing a set_xticks and set_yticks
Now we will do the same things for a second subplot. In the second position of this 2 by 2 so we type 222 when we define it.
Let’s plot this one as cos(x) and we’ll make it a blue solid line.
Similarly we will label the title and axis. and again to make it more clean, for this subplot I’m going to get rid of tick marks by doing a set_xticks and set_yticks
Now as you can imagine we do a similar thing for the third subplot. 2x2 position 3
We will make this one x squared and do a green dashed line
and we will go ahead and label the axis and give it a title
And lastly, we do the same thing for a fourth spot of our 2x2 subpltos
we will call this one fourth to stick with our theme
This will be x cubed graphed with the default color and we’ll make it be dots
Here it is. You can see the labels for each individual plot. and the titles
Let’s make it bigger so it doesn’t overlap. The reason I got rid of the tick marks was to make it less messy since we have four plots here.
There you have it that is how you make subplots using matplotlib in python
#PythonMarathon #LearnPython #PythonTutorial