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

Поделиться
HTML-код
  • Опубликовано: 12 июл 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
  • НаукаНаука

Комментарии • 69

  • @MichaelMohr-rz3wf
    @MichaelMohr-rz3wf Месяц назад

    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 Месяц назад

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

    • @KimberlyFessel
      @KimberlyFessel  Месяц назад +1

      Excellent - glad to hear it was helpful!

  • @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 😄

  • @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!

  • @massaciviankiki2532
    @massaciviankiki2532 Год назад

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

  • @avijitdey992
    @avijitdey992 11 месяцев назад

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

  • @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!

  • @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! 😄

  • @rajeshsaha9533
    @rajeshsaha9533 3 года назад

    Kudos for lucid explanation!! Thank you from India.

  • @espua72
    @espua72 2 года назад

    thank you so much for the teaching. bravo !!

  • @arnabmukherjee3129
    @arnabmukherjee3129 3 месяца назад

    So nicely explained. Thanks a lot.

  • @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 RUclips!
    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!

  • @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 7 месяцев назад

    This is really cool

  • @CaribouDataScience
    @CaribouDataScience Год назад

    Thanks that is what I was looking for.

  • @shubhamtalks9718
    @shubhamtalks9718 3 года назад

    You just saved one life today❤️.

  • @tahirhanif9669
    @tahirhanif9669 3 года назад

    I love your videos .... thank you

  • @mohammedtahernakes
    @mohammedtahernakes 2 года назад

    Thank you so much.

  • @kevincaro3320
    @kevincaro3320 3 года назад

    Thank you so much from France :)

  • @muhammadfitrie7061
    @muhammadfitrie7061 3 года назад

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

    • @KimberlyFessel
      @KimberlyFessel  3 года назад +1

      Thanks! 😄 Will definitely continue making more videos.

  • @donfeto7636
    @donfeto7636 Год назад

    Thanks so much

  • @oscartorres5201
    @oscartorres5201 3 года назад

    Hey you are great, keep it up!

    • @KimberlyFessel
      @KimberlyFessel  3 года назад

      Hey, thank you! I appreciate the kudos! 😄

  • @lekanadenusi462
    @lekanadenusi462 2 года назад

    Okay, I love Kimberly 😭

  • @triblues7065
    @triblues7065 3 года назад

    Thank you.

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

  • @dongmeili891
    @dongmeili891 3 года назад

    Thanks.

  • @pouriaforouzesh5349
    @pouriaforouzesh5349 2 года назад

    👍🏻

  • @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").

  • @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)

  • @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 !!

  • @zouhir2010
    @zouhir2010 3 года назад

    see ya

  • @rashidkhan8161
    @rashidkhan8161 8 месяцев назад

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

  • @FelipeCampelo0
    @FelipeCampelo0 3 месяца назад

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

  • @abhishekpanjiyar8266
    @abhishekpanjiyar8266 5 месяцев назад

    is facetgrid same as pivot table plotting?

    • @KimberlyFessel
      @KimberlyFessel  5 месяцев назад

      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!!

  • @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?

  • @user-mj7vl9wk1o
    @user-mj7vl9wk1o Год назад

    How i can change position of titles please?

  • @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 10 месяцев назад

    Why you stop making videos ?

  • @ee203
    @ee203 3 года назад

    Get some sleep girl. Dark circles but great tutorial

    • @KimberlyFessel
      @KimberlyFessel  3 года назад

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

    • @ee203
      @ee203 3 года назад +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