GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • PYTHON CHARTS
  • matplotlib
  • seaborn
  • plotly
  • pandas
  • colors
  • COLORS
  • COLOR PALETTES
  • R CODER
  • R CHARTS
  • Contact
  • Español

This view

  • Original page
  • New address

GeezerVison is showing python-charts.com — Area chart in pandas

Search for a graph

HOME EVOLUTION AREA PLOT PANDAS

Area chart in pandas

Area charts are line charts with the area below the line filled. In pandas they are created with plot.area and, unlike line charts, the columns are stacked by default.

Stacked area chart

plot.area stacks the columns of the data frame on top of each other, so the top line represents the total.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

rng = np.random.default_rng(3)
df = pd.DataFrame(rng.uniform(1, 5, (12, 3)).cumsum(axis = 0),
                  columns = ["A", "B", "C"],
                  index = pd.date_range("2025-01-01", periods = 12, freq = "MS"))

df.plot.area()
# plt.show()

Stacked area chart in pandas

Unstacked area chart

Set stacked = False to draw each area from zero. Use alpha to set some transparency so all the areas are visible.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

rng = np.random.default_rng(3)
df = pd.DataFrame(rng.uniform(1, 5, (12, 3)).cumsum(axis = 0),
                  columns = ["A", "B", "C"],
                  index = pd.date_range("2025-01-01", periods = 12, freq = "MS"))

df.plot.area(stacked = False, alpha = 0.4)
# plt.show()

Unstacked area chart in pandas

Percentage stacked area chart

Divide each row by its total to represent the share of each column over time.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

rng = np.random.default_rng(3)
df = pd.DataFrame(rng.uniform(1, 5, (12, 3)).cumsum(axis = 0),
                  columns = ["A", "B", "C"],
                  index = pd.date_range("2025-01-01", periods = 12, freq = "MS"))

share = df.div(df.sum(axis = 1), axis = 0)

ax = share.plot.area(ylim = (0, 1))
ax.yaxis.set_major_formatter("{x:.0%}")
# plt.show()

Percentage stacked area chart in pandas

Colors of the areas

Choose the colors with a list or with a colormap.

import numpy as np
import pandas as pd
import matplotlib.pyplot as plt

rng = np.random.default_rng(3)
df = pd.DataFrame(rng.uniform(1, 5, (12, 3)).cumsum(axis = 0),
                  columns = ["A", "B", "C"],
                  index = pd.date_range("2025-01-01", periods = 12, freq = "MS"))

df.plot.area(colormap = "Set2", linewidth = 0)
# plt.show()

Change the colors of a pandas area chart

See also how to create an area chart in matplotlib or a stacked area chart in matplotlib.

R CODER website
Storytelling with Data

Storytelling with Data

A Data Visualization Guide for Business Professionals

Buy on Amazon
Data Sketches

Data Sketches

A journey of imagination, exploration, and beautiful data visualizations

Buy on Amazon

See also

Stacked area plot in matplotlib with stackplot

Stacked area plot in matplotlib with stackplot

Streamgraph in matplotlib

Streamgraph in matplotlib

Area chart in plotly

Area chart in plotly

Line chart in plotly

Line chart in plotly

Area chart in seaborn

Area chart in seaborn

Gantt chart in plotly

Gantt chart in plotly

Step plot in matplotlib

Step plot in matplotlib

Line plot in matplotlib

Line plot in matplotlib

Calendar heatmap in matplotlib with calplot

Calendar heatmap in matplotlib with calplot

Area plot in matplotlib with fill_between

Area plot in matplotlib with fill_between

You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.