{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Bar Chart Examples" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [], "source": [ "import altair as alt" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "outputs": [], "source": [ "from vega_datasets import data\n", "population = data.population()\n", "\n", "y2k_pop = population.query('year == 2000')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Single bar chart" ] }, { "cell_type": "code", "execution_count": 3, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", "" ], "text/plain": [ "alt.Chart(...)" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "alt.Chart(y2k_pop).mark_bar().encode(\n", " x='sum(people)',\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Bar chart" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "\n", "" ], "text/plain": [ "alt.Chart(...)" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "alt.Chart(y2k_pop).mark_bar().encode(\n", " x='sum(people)',\n", " y='age:O'\n", ")" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Pandas Series to sorted bar chart" ] }, { "cell_type": "code", "execution_count": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " | counts | \n", "title | \n", "
---|---|---|
a | \n", "9.0 | \n", "a | \n", "
b | \n", "186.0 | \n", "b | \n", "
c | \n", "49.0 | \n", "c | \n", "
d | \n", "42.0 | \n", "d | \n", "
e | \n", "16.0 | \n", "e | \n", "
f | \n", "48.0 | \n", "f | \n", "
g | \n", "58.0 | \n", "g | \n", "
h | \n", "28.0 | \n", "h | \n", "