For this, pass ‘upper center’ to the loc parameter. For example, let’s now place the legend at the upper center. You can similarly place the legend at other positions in the chart. Upskill your career right now → Example 2 – Place legend at upper center The legend is now positioned at the lower left corner of the plot. For this, we need to pass ‘lower left’ to the loc parameter. Let’s replot the above plot but with the legend at the bottom left this time. The legend is placed at the top right in this example, which matplotlib determined to be the ‘best’ location for the legend. Note that the year 2011 means the club football season starting in 2011 (that is, the 2011-2012 season). Here, we plot the goals scored by Lionel Messi and Cristiano Ronaldo in club football from 2011 to 2022. # y2 values - goals by Cristiano Ronaldo in club football # y1 values - goals by Lionel Messi in club football Let’s now look at some examples of using the above syntax –įirst, we will create a matplotlib plot with the default legend. The default value for the loc parameter is ‘best’. The string ‘best’ places the legend at a location (one among the above nine mentioned) that minimizes the overlap with the other content.Use the string ‘center’ to place the legend at the center of the axes/figure.Use the strings ‘upper center’, ‘lower center’, ‘center left’, and ‘center right’ to place the legend at the center of the corresponding axes/figure edge.You can use the strings ‘upper left’, ‘upper right’, ‘lower left’, and ‘lower right’ to place the legend at the corresponding corners.There are different location values that you can pass to the loc parameter – Earned commissions help support this website and its team of writers. When you purchase a course through a link on this site, we may earn a small commission at no additional cost to you. □ Find Data Science Programs □□ 111,889 already enrolledĭisclaimer: Data Science Parichay is reader supported. MIT Statistics and Data Science: MicroMasters® Program in Statistics and Data Science.MIT Statistics and Data Science: Machine Learning with Python - from Linear Models to Deep Learning.Google Data Analysis: Professional Certificate in Advanced Data Analytics.UC San Diego Data Science: Probability and Statistics in Data Science using Python.UC San Diego Data Science: Python for Data Science.DeepLearning.AI Data Science and Machine Learning: Deep Learning Specialization.IBM Python Data Science: Visualizing Data with Python. Harvard University Computer Science Courses: Using Python for Research.Harvard University Learning Python for Data Science: Introduction to Data Science with Python.IBM Data Engineering Fundamentals: Python Basics for Data Science.IBM Data Science: Professional Certificate in Python Data Science.Google Data Analysis: Professional Certificate in Data Analytics.IBM Data Analysis: Professional Certificate in Data Analytics. IBM Data Science: Professional Certificate in Data Science.UC Davis Data Science: Learn SQL Basics for Data Science.Standford University Data Science: Introduction to Machine Learning.Harvard University Data Science: Learn R Basics for Data Science.□ Discover Online Data Science Courses & Programs (Enroll for Free)
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |