Area Plots
Welcome to Area Plots! In this video, you'll learn about area plots, their functions, and how to create them using Matplotlib.
So, what exactly is an area plot? Also known as an area chart or graph, it displays the magnitude and proportion of multiple variables over a continuous axis, often representing time or another ordered dimension. Similar to a line plot, it emphasizes the cumulative magnitude of the variables by filling the area below the line with color.
Area plots are commonly used when comparing two or more quantities, making them effective for visualizing trends and changes over time or across different categories.
Now, let's dive into how to generate an area plot with Matplotlib. But first, let's recap our dataset: each row represents a country and contains metadata about its geographic location and development status, along with numerical data of annual immigration to Canada from 1980 to 2013.
To prepare our DataFrame, we'll set the country name as the index of each row and add an extra column representing the cumulative sum of annual immigration from each country over the specified period.
After processing the DataFrame, we'll name it df_canada. Now, let's identify the countries with the highest immigration to Canada by sorting the DataFrame in descending order of cumulative total immigration from 1980 to 2013. This reveals the top five countries: India, China, the United Kingdom, the Philippines, and Pakistan.
To generate area plots for these countries, we create a new DataFrame (df_top5) containing only the top five countries' data. We then transpose this DataFrame to ensure the years are plotted on the horizontal axis and annual immigration on the vertical axis.
Now, using Matplotlib, we import it as mpl and its scripting interface as plt. Next, we call the plot function on the DataFrame df_top5, setting kind='area' to generate the area plot. We add a title and label both axes appropriately before displaying the figure using the show function.
And there you have it! An area plot depicting the immigration trend of the five countries with the highest immigration to Canada from 1980 to 2013. Area plots are effective for illustrating cumulative data trends, making them valuable for various applications such as tracking stock market performance, visualizing population demographics, or displaying resource distribution across sectors.
In summary, area plots provide a visually appealing and intuitive way to showcase the relationship and proportion of multiple variables in a single chart.
Comments
Post a Comment