• 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
  • Seaborn
  • Matplotlib
  • ggplot2
  • Altair
  • About
    • Privacy Policy
  • Visualizing Activation Functions in Neural Networks
  • Confusion Matrix Calculator
  • Visualizing Dropout Rate in Neural Network
  • Visualizing Loss Functions in Neural Networks
  • Show Search
Hide Search

How to Make a Simple Histogram with Altair in Python?

datavizpyr · December 13, 2019 ·

Last updated on December 19, 2020

Altair is the newest to Pyhon’s Data Visualization landscape. In this post we will see a simple example of making a histogram using Python’s Altair package.

Let us import Altair as alt and also import data from vega_datasets.

import altair as alt
from vega_datasets import data

We will use weather data set from Seattle.

seattle_weather = data.seattle_weather()
print(seattle_weather.head(n=3))

The primary object in Altair to make data visualization is Chart. We provide the dataframe we want to use to Chart function and build layers of visualization on top of it.

In this example, we want to build a histogram and we can make a histogram using mark_bar() function. We specify the variable name we want to use to make histogram using encode() function as shown below.

alt.Chart(seattle_weather).mark_bar().encode(
    alt.X("wind:Q",
          bin=alt.BinParams()),
    y='count(*):Q'
)

And here is how the simple histogram looks like in Altair.

Histogram with Altair
Histogram with Altair

Related posts:

Histogram with Median Line with AltairHow To Make Histogram with Median Line using Altair in Python? Area Chart with Altair in PythonArea Chart with Altair in Python 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?

Filed Under: Altair, Histogram with Altair, Python Tagged With: Python

Primary Sidebar

Python & R Viz Hubs

  • Seaborn Guide & Cookbook
  • ggplot2 Guide & Cookbook
  • Matplotlib Guide & Cookbook
  • Confusion Matrix Calculator
  • Visualizing Activation Functions
  • Visualizing Dropout
  • Visualizing Loss Functions

Buy Me a Coffee

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

Go to mobile version