- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How to create a 100% stacked Area Chart with Matplotlib?
To create a 100% stacked Area Chart with Matplotlib, we can take the following steps −
Set the figure size and adjust the padding between and around the subplots.
Create a list of years.
Make a dictionary, with list of population in respective years.
Create a figure and a set of subplots.
Draw a stacked Area Plot.
Place a legend on the figure, at the location ''upper left''.
Set the title, xlabel and ylabel.
To display the figure, use show() method.
Example
import matplotlib.pyplot as plt plt.rcParams["figure.figsize"] = [7.50, 3.50] plt.rcParams["figure.autolayout"] = True year = [1950, 1960, 1970, 1980, 1990, 2000, 2010, 2018] population_by_continent = { 'africa': [228, 284, 365, 477, 631, 814, 1044, 1275], 'americas': [340, 425, 519, 619, 727, 840, 943, 1006], 'asia': [1394, 1686, 2120, 2625, 3202, 3714, 4169, 4560], 'europe': [220, 253, 276, 295, 310, 303, 294, 293], 'oceania': [12, 15, 19, 22, 26, 31, 36, 39], } fig, ax = plt.subplots() ax.stackplot(year, population_by_continent.values(), labels=population_by_continent.keys()) ax.legend(loc='upper left') ax.set_title('World population') ax.set_xlabel('Year') ax.set_ylabel('Number of people (millions)') plt.show()
Output
- Related Articles
- How to create a stacked area chart using JavaFX?
- How to Create a Diverging Stacked Bar Chart in Matplotlib?
- How to create a stacked bar chart for my DataFrame using Seaborn in Matplotlib?
- How to create a stacked bar chart using JavaFX?
- Horizontal stacked bar chart in Matplotlib
- How can I create a stacked line graph with matplotlib?
- How to display stacked bar chart using matplotlib in Python?
- How to create stacked bar chart using ggvis in R?
- How to create a Matplotlib bar chart with a threshold line?
- How to create horizontal stacked bar chart using ggvis in R?
- How to create a line chart using Matplotlib?
- How to create a stacked form with CSS?
- JavaFX example to create area chart with multiple series
- JavaFX example to create area chart with negative values
- Create stacked bar chart with percentages on Y-axis using ggplot2 in R.

Advertisements