• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar

Data Viz with Python and R

Learn to Make Plots in Python and R

  • Home
  • Python Viz
  • Seaborn
  • Altair
  • R Viz
  • ggplot2
  • About
    • Privacy Policy
  • Show Search
Hide Search

Area Chart with Altair in Python

datavizpyr · February 7, 2020 ·

In this post, we will see how to make simple area chart with Altair in Python. Area chart displays a quantitative variable like a line plot or density plot but coloring the area under the curve. In Altair, we can make area chart with mark_area() function.

Let us first load Altair and the needed packages.

import altair as alt
import pandas as pd
import numpy as np

We will generate data to make area chart using NumPy’s random module and create a Pandas dataframe for it.

# Generating Data
np.random.seed(42)
df = pd.DataFrame({
    'weight': np.random.normal(100, 10, 1000)
})

Our data to make are chart is ready. Now we can provide the data to Altair’s chart object and use mark_area() function to specify that we are making area chart. And then specify our x axis and y-axis variables.

alt.Chart(df).mark_area(opacity=0.7).encode(
      alt.X('weight:Q', bin=alt.Bin(maxbins=100)),
      alt.Y('count(*):Q')
)

And we get a simple area chart as shown below.

Area Chart with Altair in Python
Area Chart with Altair in Python

Related posts:

Scatter plot with regression line using AltairScatter Plot with Regression Line using Altair in Python Highlight a bar in barplot in AltairHow To Highlight a Bar in Bar Chart in Altair? Stripplot Altair with jitterHow To Make Stripplot with Jitter in Altair Python? How to remove legend boxplot Altair?8 Tips to Make Better Boxplots with Altair in Python

Filed Under: Altair, Area Chart with Altair, Python Tagged With: Altair, Python

Primary Sidebar

Tags

Altair barplot Boxplot boxplot python boxplot with jiitered text labels Bubble Plot Color Palette Countplot Density Plot Facet Plot gganimate ggplot2 ggplot2 Boxplot ggplot2 error ggplot boxplot ggridges ggtext element_markdown() Grouped Barplot R heatmap heatmaps Histogram Histograms Horizontal boxplot Python lollipop plot Maps Matplotlib Pandas patchwork pheatmap Pyhon Python R RColorBrewer reorder boxplot ggplot Ridgeline plot Scatter Plot Scatter Plot Altair Seaborn Seaborn Boxplot Stock Price Over Time Stripplot UpSetR Violinplot Violin Plot World Map ggplot2

Buy Me a Coffee

Copyright © 2025 · Daily Dish Pro on Genesis Framework · WordPress · Log in

Go to mobile version