Matplotlib Legend Tutorial || matplotlib legend outside of graph || Matplotlib Tips

Поділитися
Вставка
  • Опубліковано 8 лип 2024
  • This matplotlib legend tutorial walks you through basic and advanced options for matplotlib legends using Python code for a series of matplotlib legend examples. I start from the basics including making a matplotlib legend and the label argument. I show you how to change the matplotlib legend order, and then we thoroughly discuss the matplotlib legend location. I also demo how you can move the matplotlib legend outside of the graph. We move on to making a matplotlib legend horizontal using the ncol keyword argument. Finally, we talk about styling the matplotlib legend including changing the matplotlib legend fontsize, other font properties, the label color, removing the border with frameon, and adding a title to the legend. Last but not least, I show you how to change the matplotlib legend background color with the facecolor argument.
    0:00 Introduction
    0:24 Legend Basics
    1:50 Change Legend Order
    2:38 Legend Location
    3:41 Legend Outside Plot
    5:07 Horizontal Legends
    6:13 Legend Font Size, Properties, Color
    7:12 Legend Border, Title
    7:40 Legend Background Color
    7:54 Conclusion
    Github Code:
    github.com/kimfetti/Videos/bl...
    Related Videos:
    Full Matplotlib Tips Playlist: • Matplotlib Tips
    How to SAVE a matplotlib figure and FIX TEXT CUTTING OFF: • How to save a matplotl...
    #matplotlibtips #matplotlib #dataviz
  • Наука та технологія

КОМЕНТАРІ • 38

  • @Raiden_Amani
    @Raiden_Amani 4 місяці тому +2

    Ive come here like 20 times now .😅🤣🤣... By far the most coherrent vidoe on legends I have ever encountered.

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

      Welcome back returning customer! 😆 Seriously though, very glad the video has helped you!

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

    Amazing job as allways Kimberly! Pls never stop creating videos, it's the best didatic I've found on youtube until now.

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

      Oh thank you! Really appreciate the support 😊

  • @SomeOne-rx2xw
    @SomeOne-rx2xw 2 роки тому

    So well explained and in a very simple clear way! Thank you

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

    Your videos are golden. Thank you so much !!!

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

    Great work!

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

    thanks Kimberly

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

    Perfect as always.
    Thank you.

  • @syedmujahid9860
    @syedmujahid9860 10 місяців тому

    very nice explaination in every single video

  • @levonmcgregor6113
    @levonmcgregor6113 2 місяці тому

    I am so very happy, thank you!

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

    Hey Kimberly, nice to meet you! I just found your channel and subscribed, love what you're doing!
    I like how clear and detailed your explanations are as well as the depth of knowledge you have surrounding the topic! Since I run a tech education channel as well, I love to see fellow Content Creators sharing, educating, and inspiring a large global audience. I wish you the best of luck on your UA-cam Journey, can't wait to see you succeed! Your content really stands out and you've put so much thought into your videos!
    Cheers, happy holidays, and keep up the great work!

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

      She’s great. She explains in 5 minute what sines times takes hours digging around stack overflow and the wider interwebs and even then still not always get what you’re looking for.

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

      Awesome -- nice to meet you, too! I truly do love creating UA-cam videos, and I'm happy to meet other creators who have the same passion. Best of luck on your channel as well!

  • @yem.t.3930
    @yem.t.3930 3 роки тому

    Thank you so so much! it is so comprehensive and concise

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

      Most welcome! Glad to hear you found it helpful 😄

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

    Well explained and very usefull i think taking you as personnal teacher
    quick and efficient

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

    well good...keep on ...

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

    Love you ♥️

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

    You are a saviour mam thankyou do keep posting :)

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

    Great that you are doing your videos. Please do more of them. If you could do one or more tutorials for subplot and legends and stylings it would be excellent

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

      Definitely will continue making videos! So many more fun topics to explore -- thanks!

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

    Thanks. I have a question regarding Seaborn. When I tried violinplot it created the legend automatically, but when I used scatterplot it did not. Hopefully you can do a video on this scenario.

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

    Great job. I'm facing the following problem: I have a dataframe and I've encoded the class feature using lable encoding, which I'm using to define the color each data will be plotted through plt.scatter. I've been strugling for hours trying to creat a legend for this graph, without success. Any comments on that?

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

    hi another great video, could you explain how to deal with legend in seaborn, iIcreated a plot and legend in on top of it in the middle and nothing form the seaborn website helped me to move it out

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

    When I use 'plt.legend(bbox_to_anchor=(1,1))' to set the legend outside of the visualization, I'm unable to edit the legend using the fontsize and frameon functions. Is there a way to do this?

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

    Is there a way to put the legend on the left side (before the y spine)? I tried moving the figure to the right to make room, but still can't get the legend to appear at the left most part of the window!

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

    information on adding two or more legends to same plot would be appreciated

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

      Good one! I'll be sure to add that to my second legend video 😄

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

    how can we make legends for points or scatter plots?

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

      Hi there - if you have made a scatter plot using plt.scatter(..., label="scatter points"), you should be able to make a legend for the dots like usual with plt.legend(). Here is one example of that from matplotlib: predictablynoisy.com/matplotlib/gallery/lines_bars_and_markers/scatter_symbol.html#sphx-glr-gallery-lines-bars-and-markers-scatter-symbol-py

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

    How to use legend with 2 y axis?

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

      Good question! If you have another axis for these data that is a "twinx", you can just add a legend for both axes (ax.legend() and then ax2.legend()). If I make another legend video, I'll included this... but for now, this post should help you out: stackoverflow.com/questions/5484922/secondary-axis-with-twinx-how-to-add-to-legend

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

    how to add legends for subplot outside the plot

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

      You can still use "bbox_to_anchor" to move the legend outside the figure, even with subplots! Check out the third example in this resource: matplotlib.org/stable/tutorials/intermediate/legend_guide.html