Questions tagged [altair]

Altair is a declarative statistical visualization library for Python, based on Vega-Lite. It provides a high-level API for creating complex visualizations with minimal code. Please include code and sample data in your question.

With Altair, you can spend more time understanding your data and its meaning. Altair’s API is simple, friendly, and consistent and built on top of the powerful Vega-Lite visualization grammar. This elegant simplicity produces beautiful and effective visualizations with a minimal amount of code.


Altair provides a Python API for building statistical visualizations in a declarative manner. By statistical visualization, we mean:

  • The data source is a DataFrame that consists of columns of different data types (quantitative, ordinal, nominal, and date/time).
  • The DataFrame is in a tidy format where the rows correspond to samples and the columns correspond to the observed variables.
  • The data is mapped to the visual properties (position, color, size, shape, faceting, etc.) using the group-by operation of Pandas and SQL.

The Altair API contains no actual visualization rendering code, but instead emits JSON data structures following the Vega-Lite specification. For convenience, Altair can optionally use ipyvega to display client-side renderings seamlessly in the Jupyter notebook.

1287 questions
35
votes
2 answers

Plotly express vs. Altair/Vega-Lite for interactive plots

Recently I am learning both Plotly express and Altair/Vega-Lite for interactive plotting. Both of them are quite impressive and I am wondering what their strengths and weaknesses are. Especially for creating interactive plots, are there any big…
roudan
  • 3,082
  • 5
  • 31
  • 72
25
votes
6 answers

multiple column/row facet wrap in altair

In ggplot2, it's easy to create a faceted plot with facets that span both rows and columns. Is there a "slick" way to do this in altair? facet documentation It's possible to have facets plot in a single column, import altair as alt from…
saladi
  • 3,103
  • 6
  • 36
  • 61
20
votes
3 answers

How to add a subtitle to an Altair-generated chart

It seems like you can't add a subtitle yet to a title on a graph made using the Altair Python library. I love Altair, but according to the threads I've found Altair doesn't have a subtitling capability for a graph. Has anyone figured out how to add…
George Hayward
  • 485
  • 5
  • 12
20
votes
1 answer

altair remove or suppress automatically generated plot legend

When using the altair package I've noticed that when a chart is created a plot legend is also generated. The follow code: import altair as alt from vega_datasets import data alt.renderers.enable('notebook') cars =…
James Draper
  • 5,110
  • 5
  • 40
  • 59
18
votes
3 answers

Changing the size of Altair plot renders in Jupyter notebook

I am rendering Altair plots in Jupyter notebook (not JupyterLab) using: alt.renderers.enable('notebook') And everything works fine, however the plots are often small relative to the width of my Jupyter notebook. If I expand the width of the…
dreww2
  • 1,551
  • 3
  • 16
  • 18
17
votes
1 answer

How do you set Axis FontSize in Altair?

I would like to increase the X-Axis (or Y-Axis for that matter) fontSize to 16 (or any value) in the following Altair graph. I could not find any example in the Altair documentation here: https://altair-viz.github.io/index.html. I am using Jupyter…
oekici
  • 349
  • 1
  • 5
  • 12
14
votes
2 answers

Can we plot image data in Altair?

I am trying to plot image data in altair, specifically trying to replicate face recognition example in this link from Jake VDP's book - https://jakevdp.github.io/PythonDataScienceHandbook/05.07-support-vector-machines.html. Any one had luck plotting…
arjan-hada
  • 251
  • 3
  • 17
14
votes
2 answers

Order bar chart in Altair?

How can I order my bar chart so that it is in the order of greatest to least value? I tried the below code, but it isn't giving me the expected result. I would like the bars ordered 'b', 'a', 'c' (by count) df =…
max
  • 4,141
  • 5
  • 26
  • 55
13
votes
1 answer

How to adjust scale ranges in altair?

I'm having trouble getting all of the axes onto the same scale when using altair to make a group of plots like so: class_list = ['c-CS-m','c-CS-s','c-SC-m','c-SC-s','t-CS-m','t-CS-s','t-SC-m','t-SC-s'] list_of_plots = [] for class_name in…
Jaimee-lee Lincoln
  • 365
  • 1
  • 3
  • 11
13
votes
1 answer

Increase Font Size of Chart Title in Altair

I can't figure out how to increase the size of the font for the chart title in Altair. My code will only change the font size for the axis titles, but not for the chart title. Here's what I tested out: data = df bars = alt.Chart(data, title="This…
Ragnar Lothbrok
  • 1,045
  • 2
  • 16
  • 31
12
votes
2 answers

Why is Altair returning an empty chart when using log scale?

In JupyterLab, I'm using the altair python library to create a bar graph where the x-axis is a log scale, but it's only returning an empty chart. Plotting a regular bar graph works as expected and different scale types also work. I've reviewed the…
Jason
  • 153
  • 1
  • 7
12
votes
2 answers

How can I make a map using GeoJSON data in Altair?

I'm very new to mapping, and to Altair/Vega. There's an example in the Altair documentation for how to make a map starting with an outline of US states, which is created basically with: states = alt.topo_feature(data.us_10m.url,…
Jonathan
  • 10,571
  • 13
  • 67
  • 103
12
votes
1 answer

Controlling Bin Widths in Altair

I have a set of numbers that I'd like to plot on a histogram. Say: import numpy as np import matplotlib.pyplot as plt my_numbers = np.random.normal(size = 1000) plt.hist(my_numbers) If I want to control the size and range of the bins I could do…
stephan
  • 356
  • 3
  • 9
12
votes
2 answers

How to create a grouped bar chart in Altair?

How does one create a grouped bar chart in Altair? I'm trying the following but it is just producing two graphs side by side. Chart(data).mark_bar().encode( column='Gender', x='Genre', y='Rating', color='Gender' )
Kris
  • 321
  • 1
  • 6
  • 13
11
votes
1 answer

fill between 2 lines with altair

I want to highlight the area between 2 lines in Altair. I tried to look if the solution is using mark_area() but I can't find how to specify the low limit with data. my data (few lines) : index created pct_pl_transit pct_pl_transit_max 0 …
nantodevison
  • 273
  • 2
  • 11
1
2 3
85 86