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

КОМЕНТАРІ • 73

  • @sourabhkhandelwal689
    @sourabhkhandelwal689 5 років тому

    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.

  • @adilfaiz6452
    @adilfaiz6452 2 роки тому +1

    Clearest explanation I've ever seen, a huge amount of thanks to you 🙏

  • @ZiemniakZKosmosu
    @ZiemniakZKosmosu 8 років тому

    The best explanation of subplots in matplotlib that I see to this day. I think I finally get its basics.
    Thank you:)!!!

  • @chrisfetty8929
    @chrisfetty8929 4 роки тому +1

    This whole series is awesome. Learning soo much.

  • @ketan_sahu
    @ketan_sahu 4 роки тому

    You explain things in the simplest way possible. Awesome!!

  • @xuebolai4468
    @xuebolai4468 5 років тому +2

    OMG, I wish I could have seen this video earlier. Such a perfect explanation video for matplotlib!!!!!!!!

  • @sukumarhonkote9936
    @sukumarhonkote9936 7 років тому +3

    pretty impressed that you managed to divide rectangle by 6 pretty equally

  • @EdnipFrostbeard
    @EdnipFrostbeard 5 років тому

    I recommend this video for any beginner learning matplotlib. Figures and subplots are very helpful to understand.

  • @samdavepollard
    @samdavepollard 6 років тому

    Exactly what I was looking for.
    Many Thanks for sharing your knowledge (and doing it in a way that is so easy to follow.)

  • @yashpandey350
    @yashpandey350 4 роки тому +1

    Your explanation about the grid just made my day.😇😇😇😇

  • @venkateswarlu.vobbani3029
    @venkateswarlu.vobbani3029 6 років тому

    This video will be my archive for quick reference on subplots, Thanks for helping me!!

  •  8 років тому +4

    Hi, this really helped me a lot to understand subplots and grids, thank you!

    • @sentdex
      @sentdex  8 років тому +2

      +Vinícius Rodrigues dos Santos Great! Glad I could help.

  • @SanjaySingh-bn3ul
    @SanjaySingh-bn3ul 6 років тому

    Excellant... I was struggling to get the basic concept of subplot... u did it very well to explain. Thanx lot
    -- Sanjay

  • @RISHI-zr3ez
    @RISHI-zr3ez 6 років тому

    Your Explanation was awesome..its really very helpful.

  • @GAment_11
    @GAment_11 3 роки тому

    Thank you so much. Your simple explanation cleared it up in seconds.

  • @F43R15
    @F43R15 6 років тому

    Great tutorial! Do You have any idea how could two line charts be compared (in terms of visual similarity)?

  • @yuppiemacaca9520
    @yuppiemacaca9520 8 років тому

    Really appreciate it. Very useful and clear.

  • @vincentpiano25
    @vincentpiano25 5 років тому

    It's really help me a lot ! Thank you my friend.

  • @bokistotel
    @bokistotel 4 роки тому

    Great video, very informative! keep it up!

  • @guptaachin
    @guptaachin 7 років тому

    Nice. Concise and quick.

  • @lurrehsinigang2073
    @lurrehsinigang2073 7 років тому

    Thank you for this tutorial video; it was really easy to understand :D

  • @codewithlenny
    @codewithlenny 6 років тому

    can you add live graphs to subplots? It would be really cool.Especially for data analysis

  • @anakwesleyan
    @anakwesleyan 6 років тому

    6:20 is very enlightening. thank you.

  • @halehallamehhaery1803
    @halehallamehhaery1803 8 років тому

    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

  • @ThatoRampedi
    @ThatoRampedi 7 років тому

    Hey do you know how to connect ALL dots? not scatter

  • @slonbeskonechen8310
    @slonbeskonechen8310 2 роки тому

    Excellent!!! Thank you!

  • @sanjayrakshit8797
    @sanjayrakshit8797 6 років тому

    How to set title to each of the subplots? I'm getting an error when I do ax1.title

  • @SaeedAhmed-ix8nm
    @SaeedAhmed-ix8nm 6 років тому

    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.

  • @bosepukur
    @bosepukur 9 років тому

    very nice explanation

  • @jayseagal3681
    @jayseagal3681 4 роки тому

    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)

  • @RealMcDudu
    @RealMcDudu 8 років тому

    great video!

  • @ashwin81088
    @ashwin81088 8 років тому

    This guy is awesome!

  • @robindong3802
    @robindong3802 5 років тому

    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.

  • @ganeshragade4439
    @ganeshragade4439 6 років тому

    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'

  • @debashissahoo5031
    @debashissahoo5031 6 років тому

    thank you, got clear idea.

  • @Simonnz2
    @Simonnz2 9 років тому +3

    I get a error saying x,y = create_plots()
    NameError: name 'create_plots' is not defined

    • @luisortega3090
      @luisortega3090 3 роки тому

      Did you add 'def' to your function definition?

  • @awaraamin6850
    @awaraamin6850 7 років тому

    Man i dont have anything to say to you! You are very super! THANK YOU SO MUCH

  • @sushant631
    @sushant631 7 років тому

    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

  • @josegegas
    @josegegas 7 років тому

    Thank you!

  • @muhammadrummo9067
    @muhammadrummo9067 4 роки тому +1

    Can you please make a video how to use mouse click event to interactively delete some points from subplot.

    • @muhammadrummo9067
      @muhammadrummo9067 4 роки тому

      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()

  • @sumesht.a8528
    @sumesht.a8528 6 років тому

    How to do subplot with multiline curves with single common legend outside the grid

  • @MehmetMustafaICER
    @MehmetMustafaICER 5 років тому +1

    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.

    • @sarthakkamboj4604
      @sarthakkamboj4604 5 років тому +1

      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.

  • @mikemurphy1896
    @mikemurphy1896 2 роки тому

    Awesome. Black screen is easier to view. Great vid.

  • @benisonsam2240
    @benisonsam2240 5 років тому

    How would you put one big plot on the top and two small plots in the bottom?

    • @djrocker007
      @djrocker007 5 років тому

      plt.subplot(2,1,1)
      plt.subplot(2,2,3)
      plt.subplot(2,2,4)

  • @michaelfendi3402
    @michaelfendi3402 5 років тому

    UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure

  • @Shubham-ny2ce
    @Shubham-ny2ce 4 роки тому

    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.

  • @Nico-rl4bo
    @Nico-rl4bo 4 роки тому

    thanks

  • @Amy-sz4gq
    @Amy-sz4gq 7 років тому

    This is quite helpful. Do you know what this syntax means? :
    fig, ax = plt.subplots()

    • @TXfoxie
      @TXfoxie 4 роки тому

      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.

  • @AjayKumar-id7mb
    @AjayKumar-id7mb 5 років тому

    How do you add "##" to a bunch of codes?

    • @sentdex
      @sentdex  5 років тому +1

      In IDLE, alt+3 and alt+4 to undo

  • @elmirach4706
    @elmirach4706 5 років тому

    Python3.7.0. I did exactly like you did "...ax1.plt.sublot2grid(...", but code didnt run, python complains "NameError: name 'ax1' is not defined"

    • @msduff100
      @msduff100 5 років тому

      Hi you've probably already picked this up but just incase it's "ax1 = plt.sublot2grid " not "ax1.plt.sublot2grid" :o)

  • @geo3678
    @geo3678 6 років тому +1

    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!

    • @TechWithRushabh
      @TechWithRushabh 3 роки тому

      Same here. Well It's 3 years when you commented

  • @anushreecs9491
    @anushreecs9491 4 роки тому

    How to plot multiple lines on same plot

  • @omidasadi2264
    @omidasadi2264 5 років тому

    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.

    • @sentdex
      @sentdex  5 років тому +1

      %matplotlib inline%

    • @omidasadi2264
      @omidasadi2264 5 років тому

      @@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.

  • @nickt423
    @nickt423 5 років тому

    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

  • @jeremyr6034
    @jeremyr6034 4 роки тому

    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$')

  • @kamilziemian995
    @kamilziemian995 6 років тому +1

    Maybe I am just too pedantic. I think that this video should have a title "Matplotlib Tutorial 19 - Subplots".

  • @shinebaka5696
    @shinebaka5696 3 роки тому

    This code tells me I don't know shit