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 - Наука та технологія
Ive come here like 20 times now .😅🤣🤣... By far the most coherrent vidoe on legends I have ever encountered.
Welcome back returning customer! 😆 Seriously though, very glad the video has helped you!
Amazing job as allways Kimberly! Pls never stop creating videos, it's the best didatic I've found on youtube until now.
Oh thank you! Really appreciate the support 😊
So well explained and in a very simple clear way! Thank you
Your videos are golden. Thank you so much !!!
Great work!
thanks Kimberly
Perfect as always.
Thank you.
😊 -- Thanks so much!
very nice explaination in every single video
I am so very happy, thank you!
Oh so glad it helped you - cheers!
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!
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.
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!
Thank you so so much! it is so comprehensive and concise
Most welcome! Glad to hear you found it helpful 😄
Well explained and very usefull i think taking you as personnal teacher
quick and efficient
well good...keep on ...
Love you ♥️
You are a saviour mam thankyou do keep posting :)
Thanks very much - will do!
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
Definitely will continue making videos! So many more fun topics to explore -- thanks!
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.
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?
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
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?
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!
information on adding two or more legends to same plot would be appreciated
Good one! I'll be sure to add that to my second legend video 😄
how can we make legends for points or scatter plots?
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
How to use legend with 2 y axis?
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
how to add legends for subplot outside the plot
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