Seaborn FacetGrid | How to make Small Multiples with Python Seaborn | Titles, Hue, Legend

Поділитися
Вставка
  • Опубліковано 2 чер 2024
  • This Seaborn FacetGrid tutorial shows you how to make and style a FacetGrid using Python Seaborn. I first introduce you to the concept of small multiples and making Seaborn small multiples with the facet grid. We walk through the row and col options, and I then show you how to use the Seaborn FacetGrid map and map_dataframe methods to add plots to the FacetGrid. I demonstrate how to make a seaborn FacetGrid histogram as well as scatter plots. I then teach you how to style the facet grid using methods and attributes including updating the Seaborn FacetGrid title through title templates and adding axes labels. I also show you how to use sharey and ylim within the facet grid. We next talk about displaying additional categorical data through the Seaborn FacetGrid hue, and I also show you how to add a hue legend. I show you code for updating the palette and how to style a Seaborn FacetGrid KDEplot. Finally, I demo a custom Python function that you can use to customize the facet grid however you like!
    0:00 Introduction
    0:21 Intro to Small Multiples
    1:03 FacetGrid Code Basics
    5:49 FacetGrid Methods & Attributes (axes labels, titles, sharey, ylim)
    10:16 Hue & Custom Functions
    15:18 Conclusion
    Github Code:
    github.com/kimfetti/Videos/bl...
    Related Videos:
    Seaborn histplot -- • Seaborn histplot | How...
    Seaborn scatterplot -- • Seaborn scatter plot |...
    Seaborn kdeplot -- • What is kernel density...
    Full Intro to Seaborn PLAYLIST -- • Intro to Seaborn
    #seaborn #dataviz
  • Наука та технологія

КОМЕНТАРІ • 68

  • @MichaelMohr-rz3wf
    @MichaelMohr-rz3wf 22 години тому

    Spent several frustrating days looking for something like this to plug my knowledge gap. Exactly what I needed...world's greatest tutorial!

  • @md.humayun-bin-akram9479
    @md.humayun-bin-akram9479 8 днів тому

    Your explanation saves me a lot of time. Thanks a lot.

  • @avijitdey992
    @avijitdey992 9 місяців тому

    I have never seen an explanation so beautifully put in a video. Damn! Instant subscribe

  • @arnabmukherjee3129
    @arnabmukherjee3129 Місяць тому

    So nicely explained. Thanks a lot.

  • @brianoliver7240
    @brianoliver7240 3 роки тому +2

    Thanks a lot! I now understand FacetGrid! This will be very useful.

    • @KimberlyFessel
      @KimberlyFessel  3 роки тому +1

      Awesome -- glad to hear that! I agree -- the FacetGrid (along with the catplot, relplot, etc.) are super useful. So much cool functionality!

  • @CaribouDataScience
    @CaribouDataScience Рік тому

    Thanks that is what I was looking for.

  • @massaciviankiki2532
    @massaciviankiki2532 Рік тому

    You really are saving my life with your videos! Thank you

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

    Seaborn FacetGrid is just awesome, and so is this tutorial video! Many thanks!

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

      Right?! Making these recent videos about the relplot, catplot, etc, I am really amazed at all the cool things you can do with the FacetGrid and with so little code! Cheers and thanks for the support 😄

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

    Here you are saving lives again. Or more specifically, hours of life with these thorough but succinct videos..
    Totally in love with you and your videos 🙂

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

      Why, thank you! So happy my videos have been helpful and enjoyable! 😄

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

    thank you so much for the teaching. bravo !!

  • @lekanadenusi462
    @lekanadenusi462 Рік тому

    Okay, I love Kimberly 😭

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

    Your videos are of great value, as they are concise, practical and clear. I full-heartedly recommended them on my Twitter feed for quant investors. Keep up the good work!

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

      So glad you are enjoying the videos and thank you very much for the recommendation on Twitter!

  • @BrunoAraujo-po2lm
    @BrunoAraujo-po2lm 3 роки тому +3

    Hey thank you so much for your awesome, organised and detailed didatic method! The best I've seen so far on UA-cam!
    I'd like to make a request. Can you please make a regular expressions series? I'd like to learn how to use them better on strings recognition and text manipulation.

    • @KimberlyFessel
      @KimberlyFessel  3 роки тому +1

      Oh fun - thank you for the suggestion! I enjoy regex pattern building too - especially to help out with string cleaning for NLP or for data extraction during web scraping. I will definitely add it to the list. Glad to hear you are enjoying the content so far!

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

    Hi Kimberly, thank you for the video :)
    Could you please let me know hoe exactly is the value on the y axis determined when facet grid is used? I have used it a couple of times but never figured how the y axis values are determined.

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

    Kudos for lucid explanation!! Thank you from India.

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

    Thank you so much from France :)

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

    Thank you! I was struggling with the hue's legend color and couldn't find the solution anywhere. Awesome tutorial btw.

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

      So glad this video provided you with a solution - and thanks!

  • @brandoncyoung
    @brandoncyoung 6 місяців тому

    This is really cool

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

    I love your videos .... thank you

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

    Keep it up!!! you're the best....

    • @KimberlyFessel
      @KimberlyFessel  3 роки тому +1

      Thanks! 😄 Will definitely continue making more videos.

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

    Thank you so much.

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

    Hey you are great, keep it up!

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

      Hey, thank you! I appreciate the kudos! 😄

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

    You just saved one life today❤️.

  • @donfeto7636
    @donfeto7636 Рік тому

    Thanks so much

  • @juana22793
    @juana22793 Рік тому

    Hi Kimberly! Thank you for this video. I am finding FacetGrids so useful and easy to use. The only exception is that I created 3 count plots in the FacetGrid and now I am trying to sort the bars by frequency. I created a function for this purpose to insert it in map_dataframe(), but is not working. I have tried multiple things and I cannot get my count plots to be sorted descending so they are visually easier to read. Any ideas? Thank you!

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

    Great video! I spent so many days solving the problems and finally I am here! thank you !
    I made some nice graphs but they have low resolution or low image quality when I save them as pictures, do you have any idea of that?
    thank you again :)

    • @KimberlyFessel
      @KimberlyFessel  3 роки тому +3

      Oh wonderful! Glad to hear this video helped you. There are a few different ways to save figures. Are you using matplotlib's pyplot function? If so, you can either increase your "dots per inch" or "dpi" with plt.savefig("myfigure.png", dpi=200) - the default is 100 so increasing that will increase your resolution. Or if you are okay with switching to an svg file, that could be increased with no problem since it saves the file with vectors instead of raster dots. So that would be plt.savefig("myfigure.svg").

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

    Thank you.

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

    Hi Kymberly, thanks for the video
    Can I change a different marker within each graph in the small multiples in Seaborn?

    • @KimberlyFessel
      @KimberlyFessel  3 роки тому +1

      Yes! You can do this, but it's a little tricky. If you are mapping sns.scatterplot to your FacetGrid, you'll need to include both the style and markers keywords. "style" should be set to the column name of your facets (for example, if I do "col='species'" in my FacetGrid, I'll do "style='species'" in my map_dataframe method). Then "markers" should be a dictionary where the keys are the categories in your column of interest and the values are which marker you'd like to use (for example, "markers={'Adelie': 'd', 'Chinstrap': '^', 'Gentoo': 'o'}" if I'm working with the penguin species). The full code might look like this:
      g = sns.FacetGrid(penguins, col='species')
      g.map_dataframe(sns.scatterplot, x='bill_length_mm', y='bill_depth_mm', style='species', markers={'Adelie': 'd', 'Chinstrap': '^', 'Gentoo': 'o'})
      Hope that helps!

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

      @@KimberlyFessel Thanks !!

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

    Thanks.

  • @davideeckhout4700
    @davideeckhout4700 Рік тому

    Hi, I have a question, for the 'col' argument, I have nine values. How can I make it into a grid instead of nine columns in a row? (like a 4x3 grid)

  • @rashidkhan8161
    @rashidkhan8161 7 місяців тому

    why did you add **kws parameter in function add_mean_ line ?
    please explain...

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

    👍🏻

  • @abhishekpanjiyar8266
    @abhishekpanjiyar8266 4 місяці тому

    is facetgrid same as pivot table plotting?

    • @KimberlyFessel
      @KimberlyFessel  4 місяці тому

      Yes, similar idea to the Pivot Chart in Excel. Though the facet grid can be created from the raw data instead of a pivot table.

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

    Hello @Kimberly ...thank for such an awesome video. I have been watching your other videos, they are very helpful. When followed your code exactly, I got an error:
    TypeError: add_mean_ln() missing 1 required positional argument: 'data_df'
    and got a plot without any horizontal mean line. My code is:
    def add_mean_ln( data_df, colm= None, **kws ):
    # if no x_var provided skip this altogether
    if not colm: return
    avg = np.mean( data_df[colm] )
    # get current axis
    ax = plt.gca()
    # add v-line at the grp mean
    ax.axvline( avg, color= 'red', ymin=0,ymax=1, lw= 3, ls= '--' )
    # annotate grp mean
    x_pos = 0.65
    if avg > 5000: x_pos = 0.2
    ax.text( x_pos,0.7, s= f'mean = {avg:.0f}',
    transform= ax.transAxes, # (1,1)
    color= 'maroon', fontweight= 'bold', fontsize= 12
    )
    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
    And this is how I called the facetGrid- using auto_mpg data ( my facetGrid is working well, if I don't use the custom plot function )
    fctGrd1 = sns.FacetGrid( data= auto_df, col= 'cyl_class', row= 'wt_class' )
    fctGrd1.map_dataframe( sns.kdeplot, x= 'mpg' ) #

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

      Hi there - so glad you found the video useful and that you tried out the code! There's one tiny detail causing this error. The function called "add_mean_ln" needs to take in a positional argument called "data" and NOT "data_df". Strange that it has to be exactly that, but seaborn requires that any function applied via FacetGrid's map_dataframe() MUST have a position argument called exactly "data", which is how it will pass in the data from each facet. Hopefully that clears things up! Cheers!

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

      @@KimberlyFessel Wow thanks, it works like a charm! This creating custom func for plotting will go a long way for me....
      Thanks for this video and channel. Your explanation are truly cogent, concise and easy-to-understand. Wish I had a teacher like you during my undergrad.
      People like you makes (online) learning possible and pain-free :) Cheers!!

  • @user-mj7vl9wk1o
    @user-mj7vl9wk1o Рік тому

    How i can change position of titles please?

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

    see ya

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

    I did type (g) and got “ NameError: name ‘g’ is not defined. But I can direct use g.

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

      Oh noes! Did you execute the cell above where we assign the result of the FacetGrid to the variable g?

  • @FelipeCampelo0
    @FelipeCampelo0 Місяць тому

    I can’t like twice so here we go
    👏👏👏

  • @statisthong6946
    @statisthong6946 Рік тому

    culmen_depth_mm, culmen_length_mm are not exist but there are bill_depth_mm, bill_length_mm

  • @Allinone-ck2lc
    @Allinone-ck2lc 2 роки тому

    What is dat.query

  • @TaxMentors
    @TaxMentors 8 місяців тому

    Why you stop making videos ?

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

    Get some sleep girl. Dark circles but great tutorial

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

      Haha 😴😴 Appreciate the concern, but alas, my dark circles are a result of allergies and genetics. Glad you liked the tutorial nonetheless.

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

      @@KimberlyFessel you are actually gorgeous the way you are.

  • @ujjwaltarway1438
    @ujjwaltarway1438 Рік тому

    please dont add adds in between the lecture as it disturbs the concentration please