Seaborn scatter plot | How to make and style a scatterplot in Python seaborn

Sdílet
Vložit
  • čas přidán 23. 07. 2024
  • This seaborn scatter plot video covers what a scatter plot is and how to make a scatterplot using Python seaborn. I also explain how to style your scatter plots by changing the marker size, the marker color, and marker style. Each of these three properties can also be used to convey additional information in your seaborn scatterplot.
    0:00 What is a scatter plot?
    0:58 CODE - How to build a scatter plot in seaborn
    3:43 Showing information through marker color, style, and size
    4:15 CODE - Marker color, style, size in seaborn
    9:10 CODE - Styling the marker with matplotlib
    10:30 Conclusion
    Github code:
    github.com/kimfetti/Videos/bl...
    #seaborn #dataviz
  • Věda a technologie

Komentáře • 41

  • @vitorribeirosa
    @vitorribeirosa Před 2 lety

    Thank you so much for sharing these content. I have watched several of your videos and they have made my life at lab way better.

  • @AmanSingh-vo1fh
    @AmanSingh-vo1fh Před 2 lety +2

    Thanks a lot mam
    I have recently begun my DS journey and have referred to many amazing tutorials for numpy, pandas , matplotlib etc. But yours was the best one I have seen so far.
    Thanks again

  • @francoquispevidal1702
    @francoquispevidal1702 Před 3 lety +3

    Thanks youu!!! I spent my time watching many tutorials that helped me very little until I found your CZcams channel. Your videos are definitely the best.

  • @katharinabuelow9660
    @katharinabuelow9660 Před 3 lety +1

    Thank you, that was very helpful!

  • @saharatnulor7453
    @saharatnulor7453 Před 4 měsíci

    This video is very helpful. Tank you

  • @arul7467
    @arul7467 Před 3 lety

    thanks!! this helped a lot

  • @gustavoviana1178
    @gustavoviana1178 Před 2 lety

    hey nice video!

  • @alexisrangelcalvo6781
    @alexisrangelcalvo6781 Před 2 lety

    Thanks a lot!

  • @debatradas9268
    @debatradas9268 Před 2 lety

    thank you so much maam

  • @mohammed_Ansar
    @mohammed_Ansar Před 3 lety

    i love your vedios.. you will make me data analyst soon..

  • @vaibhavarora9408
    @vaibhavarora9408 Před 3 lety +1

    Thanks!

  • @evanwright640
    @evanwright640 Před 2 lety

    How do you make a midpoint for the colors?

  • @vedansh4033
    @vedansh4033 Před 2 lety

    on setting hue, cuts with value zero like 'fair', 'ideal' are also getting plotted, how to get rid of them

  • @isabelahorta3063
    @isabelahorta3063 Před 2 lety

    Hi, Dr. Fessel! Thank you so much for the video! How can I add a trend line on the scatter plot?

    • @MrJojoxD
      @MrJojoxD Před 2 lety

      Try using seaborn's lmplot()

  • @peterjuhasz976
    @peterjuhasz976 Před 2 lety +1

    Hi Kimberly, Thank you very much for the course! I especially like your clear explanations. I would like to add some information. I am using seaborn 0.11.2. In the diamond dataset cut, color and clarity are now type of category. So the filtered out values also appear on legend when hue is used. They also appear when you type diamonds['cut'].value_counts() with count 0. To avoid this I changed the these fields back to string with diamonds['cut'] = diamonds['cut'].astype('str'). Do you have a better solution for this? And please add this information to your notes or to the new version of this video. Thank you again.

  • @luvpurohit7488
    @luvpurohit7488 Před 3 lety +2

    great set of videos,could you also do one to explain which plots to use when , i know it comes with practice

    • @KimberlyFessel
      @KimberlyFessel  Před 3 lety +2

      Thanks -- I love this idea! I have been thinking about doing a few videos showing my thought process when selecting which figure to use and how I select my styling. It definitely comes with practice and depends on the data story, but maybe it would be helpful to show the thought process for a few examples. 👍

    • @manavsaxena5579
      @manavsaxena5579 Před 3 lety +1

      @@KimberlyFessel Yes please! As a beginner, I mostly end up using bar plot, histograms and scatter plots. I would really appreciate if you could make a video on this.

  • @ASmallGreenBean
    @ASmallGreenBean Před 3 lety

    Hi! Could you explain how you get the legend to show the correct 'custom' markers, if this is even possible? (Referring to 9:10)
    Thanks a lot for these videos!

    • @KimberlyFessel
      @KimberlyFessel  Před 3 lety

      Hi there -- the legend in the figure you referenced was autogenerated by Seaborn, so you can match up the hue to the diamond cut and the marker shape to the diamond color. But a couple of things:
      1. With the most recent update, Seaborn treats many columns as the "category" data type rather than strings. This means that if you do the filtering like I did in this video (with the old version of Seaborn), you will see many unused categories in the legend. You can either convert these columns to strings (with pandas .astype() method) or drop these unused categories (with pandas cat.remove_unused_categories() method: pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.cat.remove_unused_categories.html#pandas.Series.cat.remove_unused_categories) to make your legend look like mine.
      2. Also -- you can create your own custom legend if you'd like to match up the color and marker and, say, use a labels like "Premium, F", "Premium, D", etc. This StackOverflow post walks you through how you could do that: stackoverflow.com/questions/54682473/change-legend-location-and-labels-in-seaborn-scatter-plot

  • @muhdhazim5857
    @muhdhazim5857 Před 3 lety

    hi, may I know how to change hue that shows the legend into the colorbar?

    • @KimberlyFessel
      @KimberlyFessel  Před 3 lety

      Hi there - once you create your color bar you can just add it to the figure and remove the current legend. This reference should be able to help you out: stackoverflow.com/questions/62884183/trying-to-add-a-colorbar-to-a-seaborn-scatterplot

  • @Himanshu-ed3mf
    @Himanshu-ed3mf Před 3 lety +2

    Though 'cut' column contains only two categories: 'Premium' and 'Good' but in legend it is showing all the categories. How it is possible?

    • @KimberlyFessel
      @KimberlyFessel  Před 3 lety +3

      Yes, this is a relatively recent seaborn update. The data that come with seaborn have "category" data types for the strings. This means they have a property called .cat.categories. This gives all the categories (even the ones that aren't present), and this is what seaborn builds the legend from. You can override this either by not having the category data types (converting to strings, say) or by setting hue_order like I did in my recent countplot video here: czcams.com/video/8U5h3EJuu8M/video.html

  • @simplemente_humano
    @simplemente_humano Před 3 lety

    Excellent tutorial. Learned a lot. :)
    In minute: 1:32, what does the argument random_state means? And why did you choose = 22?

    • @KimberlyFessel
      @KimberlyFessel  Před 3 lety

      Hi there -- random_state just allows for reproducibility. Since I'm selecting a random subset of the data, using random_state sets the seed of my random number generator. That means if you run this code, you will get the same random rows as me.
      And the number 22 is completely arbitrary! I often choose 42 in honor of "The Hitchhiker's Guide to the Galaxy." :) But you can pick any number you'd like.

    • @simplemente_humano
      @simplemente_humano Před 3 lety +1

      @@KimberlyFessel Thank you😃

  • @nsnilesh604
    @nsnilesh604 Před 2 lety

    How to write text i want to show with scatter plot

    • @KimberlyFessel
      @KimberlyFessel  Před 2 lety

      Hi there - you can add text to seaborn figures by using matplotlib pyplot's text function. And here is my past video on that: czcams.com/video/NBYzSaTbodM/video.html You can even automatically update the text positions so they don't overlap on the scatterplot using a library called AdjustText (Video here: czcams.com/video/xSS59Ga64rQ/video.html)

  • @judetochukwuogbozor6355

    I love you Kimberly🤩🤩🤩🤩

  • @kannan.s566
    @kannan.s566 Před 2 lety

    Also explain remaining parameters

  • @kyleparsotan6799
    @kyleparsotan6799 Před 2 lety

    Tried to annotate the figure:
    #plt.text(x_pos, y_pos, f"y = {m:.2f}x {b:.1f}", bbox=dict(facecolor='white', alpha=0.5))
    #plt.text(5, 5, f'R$^2$ = {R_value:.4f}', bbox=dict(facecolor='red', alpha=0.5))
    plt.annotate(
    # Label and coordinate
    'R$^2$ = {R_value:.4f}', xy=(5, 50), xytext=(0, 80),
    # Custom arrow
    bbox=dict(facecolor='red', alpha=0.5))
    but my y values no matter what way I try isn't going up or down.