Matplotlib Tutorial 19 - subplots
Вставка
- Опубліковано 10 лип 2015
- In this Matplotlib tutorial, we're going to be discussion subplots. There are two major ways to handle for subplots, which are used to create multiple charts on the same figure. For now, we'll start with a clean slate of code. If you're following along linearly, then make sure to keep the old code on hand, or you can always revisit the previous tutorial for the code again.
sample code: pythonprogramming.net
hkinsley.com
/ sentdex
sentdex.com
seaofbtc.com
Thanks, dude! You are just awesome. I was scratching, banging against a wall my head after reading the docs, you as always are a life saviour.
Clearest explanation I've ever seen, a huge amount of thanks to you 🙏
The best explanation of subplots in matplotlib that I see to this day. I think I finally get its basics.
Thank you:)!!!
This whole series is awesome. Learning soo much.
You explain things in the simplest way possible. Awesome!!
OMG, I wish I could have seen this video earlier. Such a perfect explanation video for matplotlib!!!!!!!!
pretty impressed that you managed to divide rectangle by 6 pretty equally
I recommend this video for any beginner learning matplotlib. Figures and subplots are very helpful to understand.
Exactly what I was looking for.
Many Thanks for sharing your knowledge (and doing it in a way that is so easy to follow.)
Your explanation about the grid just made my day.😇😇😇😇
This video will be my archive for quick reference on subplots, Thanks for helping me!!
Hi, this really helped me a lot to understand subplots and grids, thank you!
+Vinícius Rodrigues dos Santos Great! Glad I could help.
Excellant... I was struggling to get the basic concept of subplot... u did it very well to explain. Thanx lot
-- Sanjay
Your Explanation was awesome..its really very helpful.
Thank you so much. Your simple explanation cleared it up in seconds.
Great tutorial! Do You have any idea how could two line charts be compared (in terms of visual similarity)?
Really appreciate it. Very useful and clear.
It's really help me a lot ! Thank you my friend.
Great video, very informative! keep it up!
Nice. Concise and quick.
Thank you for this tutorial video; it was really easy to understand :D
can you add live graphs to subplots? It would be really cool.Especially for data analysis
6:20 is very enlightening. thank you.
hi, I have a question:
if we have a set of y-axis data point with two x_axis (y_axis is shared). how can I plot the data in a way that I get one point at each y_point and 2 x_point (x_1,x_2,y) . for example, I want to show an object's Temperature on one x-axis and on the second x-axis the conductivity of the object and y-axis would be density.when I plot it I get two point which are shifted from each other.
many thanks for the help
Hey do you know how to connect ALL dots? not scatter
Excellent!!! Thank you!
How to set title to each of the subplots? I'm getting an error when I do ax1.title
I really like python because of you. I have a question I want to include the time stamp and the on the x-axis i should i have time stamp and on the y axis i need a value. can you please tell me how i can achieve this I am using python 2.7 32bit on windows 10.
very nice explanation
i am using lists to plot a graph but my graph makes the same pattern everytime as it uses the previous plotted values from the list and plot the point from the start of the list after every 5 secounds(interval)
great video!
This guy is awesome!
Dear instructor, my style.use('fivethirtyeight') always in red, but no errors. so I could not make plt.show() work, any idea?
my TF is 1.10 and python 3 on colab by google. thank you very much.
thank you very much for your video after executing this program i got following error please help me if you can
ani=animation.FuncAnimation(fig, animate, interval=1000)
AttributeError: 'function' object has no attribute 'FuncAnimation'
thank you, got clear idea.
I get a error saying x,y = create_plots()
NameError: name 'create_plots' is not defined
Did you add 'def' to your function definition?
Man i dont have anything to say to you! You are very super! THANK YOU SO MUCH
it shows error 'Unresolved reference' when i import like this:
from matplotlib import style
is it not allowed in 3.6 or what ??
i have been using matplotlib.style due to this reason
Thank you!
Can you please make a video how to use mouse click event to interactively delete some points from subplot.
Something like what I have tried but did not work :
import matplotlib.pyplot as plt
x = [1, 2, 3, 4]
y = [2, 5, 6, 5]
def onpick(event):
this_artist = event.artist
print(this_artist)
plt.gca().picked_object = this_artist
def on_key(event):
if event.key == u'delete':
ax = plt.gca()
if ax.picked_object:
ax.picked_object.remove()
ax.picked_object = None
ax.figure.canvas.draw()
fig, ax = plt.subplots()
ax= plt.scatter(x,y)
fig.canvas.mpl_connect('pick_event', onpick)
cid = fig.canvas.mpl_connect('key_press_event', on_key)
plt.show()
How to do subplot with multiline curves with single common legend outside the grid
First of all thanks. This is a great pure gold video. Explained a lot. I have a question.
At 6:00, why the third plot (wide one at the bottom) is 2x1x2. I did understand it should be 2x1. But why it is 2 at the end. Why it is not (211) instead of 212. I tried 211 and it basically places on the top row. Can you guys explain? I googled it a lot. Still did not get the logic. Thanks.
211 would plot it on the top as the last 1 corresponds to the top section in the 2x1. 211 means in a 2x1, you want to plot corresponding to the second section, which in this case is the section on the bottom.
Awesome. Black screen is easier to view. Great vid.
How would you put one big plot on the top and two small plots in the bottom?
plt.subplot(2,1,1)
plt.subplot(2,2,3)
plt.subplot(2,2,4)
UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure
why bottom rectangle got 212 as its parameter. I understand 2 and 1 but why plot number 2 ? It is the 1st plot in its row.
thanks
This is quite helpful. Do you know what this syntax means? :
fig, ax = plt.subplots()
you can use fig, ax = plt.subplots() for some easy and even subplots but if the subplots are uneven and irregular, then we need to introduce gridspec. Actually Sentdex's two ways, add_subplot/subplot2grid are good enough to deal with most of even or uneven subplots.
How do you add "##" to a bunch of codes?
In IDLE, alt+3 and alt+4 to undo
Python3.7.0. I did exactly like you did "...ax1.plt.sublot2grid(...", but code didnt run, python complains "NameError: name 'ax1' is not defined"
Hi you've probably already picked this up but just incase it's "ax1 = plt.sublot2grid " not "ax1.plt.sublot2grid" :o)
The tutorials are awesome! Thank you very much for that!
I have a few questions, hopefully somebody can help me out:
I do not fully get the reason why you use fig = plt.figure() in the beginning. What is it good for? You can also create these graphs without it. Until now, I didn't find any video where this is explained. Especially, I do not understand why you use it in connection with plt.subplot2grid() in several videos (e.g. ua-cam.com/video/P90mCSsGE1c/v-deo.html). You do not refer to the figure anymore in following code ( also fig.subplot2grid() creates an error for me). Why/how is it useful then?
Is there any video where this is explained? Thanks for your help!
Same here. Well It's 3 years when you commented
How to plot multiple lines on same plot
I tried to do it on jupyter notebook, but it need to rerun again and again..... guys I can't believe that this is the only way to see the graph during the process.
in matlab this works just by a 'hold' parameter.
%matplotlib inline%
@@sentdex thanks bro, but I want to see the plot's changes in every iteration... unfortunately it appears after whole process and show the entire results at last.
You videos are awesome but I think your videos would be better if you told us a little more about how each component of the code works. A lot of times you'll just say how to do things without really explaining why
def Lorenz(current_values, t, sigma, beta, rho):
"""The famous chaotic Lorenz equations."""
# unpack the variables
#sigma,beta, rho
u, v, w= current_values ### added w
# form the derivative we neee to pass back
dudt = sigma*(v - u)
dvdt = rho*u - v - u*w
dwdt = u*v -beta*w ### added differnetial fro w
# all done, let's gather our results and exit!
return [dudt, dvdt, dwdt] ### returned diffy for W
# 3 - choose the initial condition (where to start)
u0 = 0
v0 = 1
w0 = 1.05
initial_conditions = np.array([u0, v0,w0]) ### added w initial
# 4 - choose time interval over which we want a solution
time_max = 60
num_time_points = 4000
time = np.linspace(0, time_max, num_time_points) ### filled this out to make a time array
# 5 - choose values for the parameters
sigma = 10
beta = 2.667
rho = 26
# 6 - all set! let's get the solution in one line, and unpack it!
Lorenz_solution = odeint(Lorenz, initial_conditions, time, args = (sigma, beta, rho))
# unpack so that we can see what we got, using Numpy slicing
u_new = Lorenz_solution[:,0]
v_new = Lorenz_solution[:,1]
w_new = Lorenz_solution[:,2]
# 7 - let's visualize what we got
fig = plt.figure(figsize=(20,10))
plt.plot(time, u_new, label='u')
plt.plot(time, v_new) ###plotted v
plt.plot(time, w_new) ### plotted w
plt.grid(alpha=0.2)
plt.legend()
plt.title('Solution of the Lorenz System')
plt.xlabel('time')
plt.ylabel('$u, v, w$')
Maybe I am just too pedantic. I think that this video should have a title "Matplotlib Tutorial 19 - Subplots".
This code tells me I don't know shit