Questions tagged [altair]
Altair is a declarative statistical visualization library for Python, based on Vega-Lite. Please include code and sample data in your question.
1,053
questions
3
votes
1
answer
27
views
How to install a new font in altair and specifying it in alt.TitleParams
I am wondering if it's possible to install fonts to use in altair to use in alt.TitleParams. For this example, without font specified, I get a default font and size.
import altair as alt
import pandas ...
2
votes
1
answer
26
views
Testing Python code that produces Altair graphs
Is there a recommended way to write tests for Python code that generates graphs using Altair?
A simple example is:
df = pandas.DataFrame(...)
chart = alt.Chart(df).mark_point().encode(x='...', y='...')...
0
votes
1
answer
23
views
Altair interactive filter on multiple values of one column
Here is the code of my plot.
input_dropdown = alt.binding_select(options=[None]+all_ids, name='Series ID', labels=["All"]+all_ids)
selection = alt.selection_single(fields=['ID'], bind=...
0
votes
1
answer
37
views
How can I add math symbols to altair plots?
Is there a way to add mathematical symbols like beta, alpha, epsilon, etc. into altair plots?
I'd like to be able to add them really wherever — e.g., axis titles, text marks, ...
Is this possible? I ...
1
vote
0
answers
18
views
Trying to display a chart using vegaEmbed and a JSON object generated with altair. vegaEmbed is interpreting JSON object as URL. Any alternatives?
so sort of a niche question, but I was hoping someone else knew the answer to this, I haven't found anything useful in the vega or altair documentation.
So to start off, this is the situation:
I am ...
0
votes
1
answer
13
views
Remove legend for points in Altair
I'm following this example https://altair-viz.github.io/gallery/multiline_highlight.html, and added text points. My lines have both strokeDash and color.
import altair as alt
from vega_datasets import ...
2
votes
1
answer
61
views
Changing the width of a step in Altair line and area charts
I try to build a line chart that displays a value for each month of a full year. I also want to fill months that exceed a threshold. I have an issue with the appearance of the last values of both the ...
1
vote
1
answer
40
views
In Altair/Vega-lite how to show percentage of grouped category instead of total?
Newbie using Altair/Vega-lite and struggling a bit to "get" the transformations and calculations and encoding way of thinking, especially for more complex/nested data.
Specifically, I am ...
1
vote
1
answer
40
views
Is there a way to change the default resolution for downloading .png images from jupyter notebooks in Altair?
Is there a way to change the default Altair settings such that, when I click (...) in the upper right-hand corner of a figure in a jupyter notebook and then select "Save as PNG", it saves ...
1
vote
1
answer
21
views
Show selection box over multiple rows in Altair
I want to create a plot using altair that spans multiple rows and is interactive. Highlighting a subregion of the plot correctly highlights that region in all rows by changing the color outside that ...
1
vote
1
answer
36
views
How to make Altair display NaN points with a quantitative color scale?
In Altair, is there a way to plot NaN/None colors in quantitative encodings? Possibly even assigning a specific color such as in Matplotlib's set_bad?
For example, the third data point is missing ...
0
votes
1
answer
42
views
Mirror/invert graph in a repeating bar graph - Altair
I am making a repeating bar chart that currently looks like this:
original graph
but I need each bar graph to be mirrored so that each graph looks relatively like so:
mirrored graph
I have ...
0
votes
2
answers
60
views
How to round numbers in Altair
I have a graph that instead of using count() as Y axis I used percentage. I would like to show only the round number and see the whole number 39%, 24%, 37%.
activities = pd.DataFrame({'Activity': ['...
2
votes
1
answer
30
views
How to increse label spacing and tick spacing in case of multiple y-axis in altair?
I am trying to increase the legibility of the plot since both the y-axis labels(on left) have got overlapped and adjust the tick range and interval between them.Kindly help me in doing so multi axis ...
0
votes
1
answer
38
views
altair and pandas connecting two specific data details
My teammate and I have extracted two sets of data specifics out of two datasets from the MoMA museum.
One is to identify the gender of the artists displayed in the museum.
df_artists = pd.read_csv('...
1
vote
1
answer
36
views
Altair repeated chart, add different subplot/chart title
I can't believe I haven't been able to google the answer for this .... in the documented example of repeated charts, how would I add a different sub-chart titles?
import altair as alt
from ...
1
vote
1
answer
39
views
Altair transfrom_density
I am trying to replicate this graph in Altair but for some reason is don't get any information on my chart, I can only see an empty chart.
link to data
My attempt:
alt.Chart(data).transform_density('...
0
votes
0
answers
62
views
Altair: Interactive correlation matrix where you can select variables
I have a correlation matrix with well over 50 different variables that can correlate (not the data shown here), and I would like to create an interactive correlation matrix in Altair where you can ...
1
vote
1
answer
46
views
Altair LOESS Smoothing with Date
i liked making Plots with Altair lately, unfortunately Smoothing of Timeseries doesn't work that well.
So this is my base plot (the data doesn't really need smoothing, but let's ignore that)
import ...
0
votes
3
answers
47
views
How to add % into Pandas pivot table using Altair
I am working on a survey and the data looks like this:
ID Q1 Q2 Q3 Gender Age Dept
001 Y N Y F 22 IT
002 N Y Y M 35 HR
003 Y ...
0
votes
0
answers
34
views
The altair library graph is not displayed
I'm running codes on VScode but the graph is not showing
import numpy as np
import pandas as pd
import altair as alt
df = pd.DataFrame({"x1": [0, 2], "y1":[8, 3], "x2": [...
2
votes
1
answer
58
views
Configuring the Title and Axes for an Altair Graph
I was recently learning how to use Altair to create graphs, and had some trouble customizing the title and axes. My code for the graph currently looks like:
chart = Chart(data).mark_bar().encode(
...
1
vote
1
answer
34
views
Undefined X-axis using Altair
I am trying to generate a stacked bar graph using the Altair package, but I'm having trouble with the x-axis. I expected my graph to look something like this, but instead all of the categories for the ...
2
votes
1
answer
32
views
Changing the "save as" filename for Altair chart in google colab
I'm using altair in google colab and would like to create and download charts with a custom filename instead of 'visualization.svg'. I need to do this for about ~50 charts, I don't mind clicking '...
0
votes
1
answer
33
views
How to format the last line segment based on a datetime column?
I'm trying to make the final segment of a line plot dashed to indicate incomplete data. From what I can tell I should be able to do this using a condition on strokeDash. However I can't figure out how ...
0
votes
1
answer
15
views
Problem plotting data in altair, data is swapped in pyramid graph
I am trying to plot the data from my pd file that contains data about man and woman in different function levels. However whilst plotting the pyramid df the data is swapped. PhD and assistant are ...
0
votes
1
answer
23
views
Adding Name to tooltip in altair-python
I'm trying to add movie title names and rating to a violin plot so when you scroll it shows both name and rating. My code is as follows:
import altair as alt
plot = alt.Chart(data_trim)....
1
vote
1
answer
23
views
Add Vertical Lines With Same Encodings as "Corresponding" Curve in Altair
I have a situation like this:
from scipy.stats import norm as norm_dist
import numpy as np
import altair as alt
import pandas as pd
grid = np.linspace(-5, 5, 1000)
mean_1 = 1
mean_2 = 2
dists_data = ...
1
vote
1
answer
30
views
How can I apply clipping to mark_text() in altair?
I have my plot clipped so it only shows certain ranges on the y axis. I added text to it using this code:
text2 = plot2.mark_text(align='left', dx=5, dy= -8, size = 15).encode(text = alt.Text('...
0
votes
1
answer
51
views
Remove repeating values from X axis label in Altair
I am having trouble with Altair repeating X axis label values.
Data:
rule_abbreaviation flagged_claim bill_month
0 CONCIDPROC 1 Apr2022
1 CONTUSMAT1 1 ...
1
vote
1
answer
59
views
how to use quantileNormal in altiar with labelExpr
I have a dataset df that contains a computed frequency curve that looks like
aep flow variance n-day
0 0.001 64480.8 0.01190750 01-day
1 0.002 56995.7 0.00925476 01-day
2 0.005 ...
1
vote
1
answer
44
views
Python Altair, pin text to bottom-right of chart
How do I pin a piece of text, for example with mark_text(), to the bottom-right of the chart, so that it stays at the bottom-right corner of the chart, even when the chart is resized with, say, ....
1
vote
1
answer
50
views
How to create a JS file from python graph
I have used altair to create graphs using python. So I have used following code to save the chart.
chart.save('chart.html', embed_options={'actions': False})
My chart.html file look as below,
<!...
1
vote
1
answer
86
views
Setting Colors in Altair Layered Chart
Similar to Setting colors in Altair charts I am using a layered chart and I like to set excplicit colors. Somehow, when I use the solution from the answer, my colors are always changing to some ...
2
votes
1
answer
81
views
How to use vegaEmbed to embed an Altair visualization into html document?
I am trying to embed an Altair data visualization I created in Python, into an html document. I have followed the instructions on https://altair-viz.github.io/user_guide/saving_charts.html, ...
1
vote
1
answer
40
views
Second x axis or x labels
I would like to ask you if there is a way how to create a second x-axis in Altair (put the daytime on top)?
bar_cumm_TAGP = alt.Chart(df_TAGP_2[df_TAGP_2['simulation_date'] == '2020-10-
15'])....
1
vote
1
answer
45
views
Altair syntax for condition involving aggregate field
I am trying to create a condition involving an aggregate field. For this example dataset
df=pd.DataFrame([['game1','player1',2,1],['game1','player2',3,4],['game1','player3',2,2]
,['...
2
votes
1
answer
46
views
Centering the axis title between two concatenated Altair plots
I have an Altair plot that is a vertical concatenation of subplots. However, they share the y-axis title, and I would like to place this in the middle of the two plots.
For example, let's say I have ...
1
vote
1
answer
30
views
Concatenation issue of sorted bar chart layer with mark circle sorted layer in Altair
I'm trying to concatenate two sorted layers in Altair. When I do this it adds extra tick labels.
I've tried scale resolve, axis=None but it doesn't work.
In addition, it looks like this issue relates ...
1
vote
1
answer
39
views
Altair: adding sorting destroys chart
The following code produces a column chart in which the y axis grows in the wrong direction.
alt.Chart(df).mark_line().encode(
x = alt.X('pub_date', timeUnit='month'),
y = alt.Y('sum(has_kw)', ...
1
vote
1
answer
70
views
Python Altair, query for current axis limits
I know how to set axis limits and whatnot, but how do I query for currently used axis limits?
1
vote
1
answer
33
views
Configure x-axis limits after chart creation
I know I can create a chart with custom x-axis limits by, for example:
altair.Chart(source).encode(
x=altair.X("whatever", scale=altair.Scale(domain=(left_limit, right_limit))
)
But ...
1
vote
1
answer
28
views
Is there a way to apply this function onto an Altair scatter plot?
I am hoping I can apply this draw_vector function onto an Altair scatter plot rather than matplotlib. I am having trouble with a workaround. Your expertise would be appreciated!
def draw_vector(v0, v1,...
2
votes
1
answer
37
views
Issue with visualizing air raid siren duration on the plot
I try to visualize the duration of air raid sirens in my country by date and time. There is one problem I'm struggling with. When the air siren starts one day and ends the next day it fills up the ...
2
votes
1
answer
64
views
Updating a table based on plot selection by altair
For the past week, I have been trying to create an interactive altair dashboard. My goal is to create a plot connected to a table, where the table gets updated based on the selection of the plot.
For ...
0
votes
1
answer
28
views
Altair Chart Interactions & Python
I'm working through the exercises in the Altair Tutorial and am struggling in the interactions section with making one of the points in the chart larger than the rest when I hover over it. I've tried ...
0
votes
1
answer
78
views
Altair: How to make scatter plot aligned with image background created by mark_image?
I'm looking for a working example to have a .png picture as the background of a scatter chart.
Currently, I use mark_image to draw the background image:
source = pd.DataFrame.from_records([
{"...
1
vote
1
answer
29
views
Python Altair how do I skip (or squeeze) part of the x axis?
Say I have data indexed by date time (pd.Timestamp type), but I know for certain that between certain times each day, there is no data (financial data for example), and I would like to plot data over ...
2
votes
1
answer
32
views
HConcat of mark_geoshape and mark_bar breaks depending of order
I'm trying to produce a Vega/Vega-Lite chart using Python and Altair. The following code returns a Javascript Error:
map_ = alt.topo_feature('https://raw.githubusercontent.com/ginseng666/GeoJSON-...
0
votes
1
answer
61
views
Python Altair, `mark_line()`, _ignore_ NaN instead of _skipping_ them or treating them as 0?
As far as I can see, for example here, the only two ways Altair handles NaNs is either "filter" or None. In the context of mark_line(), "filter" means that the NaN will be skipped, ...