• 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

How to Make a Simple Histogram with Altair in Python?

datavizpyr · December 13, 2019 ·

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

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