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.

Filter by
Sorted by
Tagged with
0 votes
0 answers
25 views

How is it possible to turn an jupyter notebook that uses altair, pandas and ipywidget into workable .py that i can throw into an exist page?

I learned python through IPython Notebooks and scrambled together but I want to know if it is possible to take the notebook and sort of paste it it with its own route? Or can I upload the notebook ...
elksie5000's user avatar
  • 7,064
0 votes
0 answers
18 views

Plot several vertical lines with different x values per faceted graph in Altair

I'm running into an issue with plotting vertical lines on top of other Altair's marked lines (represented by 'posterior' and 'prior' here) where the prior and posterior lines become swiveled after ...
Valerie's user avatar
0 votes
0 answers
15 views

How to implement autoselect using Altair, ipywidgets and pandas

This is a bit of code that I'm trying to tidying up that I realised doesn't function properly. It's a relatively large dataset so my initial approach was to subset the data using a filter that I could ...
elksie5000's user avatar
  • 7,064
0 votes
0 answers
25 views

Is there a way to make multi-colored titles in Altair?

I'm trying to make a multi-colored Altair chart title. I have a grouped bar chart with two columns (e.g. A and B) in different colors (e.g. red and blue), and I wanted the title to be something like &...
Maisa Fraiz's user avatar
0 votes
0 answers
14 views

Is it possible to have BBox's on labels in Altair?

I have a chart similar to this but with less data points. I want to add BBox's to the labels ideally As a bonus question how would If I had this many labels would I only display a certain number of ...
Peter Skeels's user avatar
0 votes
0 answers
8 views

How to color both points and lines on mouseover in Vega Altair?

In a Chart created with mark_point() + mark_line(), I want to hover the mouse over a line and highlight it with a color. Here's the code: import altair as alt from vega_datasets import data cars = ...
Stopfield's user avatar
0 votes
0 answers
11 views

Marks misaligned in Altair Gantt chart when axis labels are wrapped

I'm generating a Gantt chart using Altair v5.1.1 and I find that, when I try to implement multi-line axis labels, some marks are misaligned. The data: df = pd.DataFrame([{'Dataset': 'A - Lorem ipsum ...
iff_or's user avatar
  • 890
0 votes
0 answers
14 views

Reset Zoom of Interactive Altair

I would like to have a way (button for example) to reset the zoom in or zoom out to some start of an interactive plot from altair. Here is some reproducible code: import altair as alt from ...
Quinten's user avatar
  • 35.5k
0 votes
1 answer
29 views

How to fix Altair error when code appears to be right

Name Gender Value Year Measure 0 A boy 3451 2021 Rank 1 A-Jay boy 3451 2021 Rank 2 A.J. boy 0 2021 Rank 3 Aaban boy 3990 2021 ...
elksie5000's user avatar
  • 7,064
1 vote
1 answer
24 views

Make only one value to be a unique shape in Altair point graph?

I'm using Altair to make a point graph where all the shapes are the same (circle) for each stock value except for one (let's say diamond). In this dataset I want the stock symbol for "V" to ...
engineer-x's user avatar
  • 2,227
1 vote
1 answer
46 views

Squeeze x-axis dates on altair line chart

I have a burndown graph that shows dates on the x-axis and remaining objects on the y-axis. Sometimes I have a large amount of "stagnant" data (no objects completed for X-amount of time). ...
Binx's user avatar
  • 382
0 votes
0 answers
22 views

Nested axis labels in altair plot?

It it possible to create nested in altair, similar to this from the ggh4x package?
Revan's user avatar
  • 2,082
0 votes
0 answers
12 views

pywebview "Save as PNG" unresponsive

I have a project using pywebview to display some data that I charted using Pandas and Altair. When using the interactive window that displays the charts, each chart has an option menu to save the ...
KJ0797's user avatar
  • 187
0 votes
1 answer
15 views

vega-altair in jupyter notebook: can't add labels to a scatter chart with a regression line or vice versa?

I can plot a scatter chart with a regression line, and I can plot a scatter chart with a text label on each point. When I try to do both I get: Javascript Error: Duplicate signal name: "...
wgm20's user avatar
  • 1
0 votes
0 answers
16 views

How to initialise an Altair plot

I have some python code to create a plot in altair. # Create dropdown selections result_dropdown = alt.binding_select(options=melted_df['Major region'].unique().tolist(), name="Local authority: &...
elksie5000's user avatar
  • 7,064
1 vote
1 answer
37 views

How to hover and hightlight single line in chart in Altair

# Create dropdown selections result_dropdown = alt.binding_select(options=melted_df['Major region'].unique().tolist(), name="Local authority: ") result_selection = alt....
elksie5000's user avatar
  • 7,064
0 votes
0 answers
14 views

Altair tooltip: avoid showing missing entries

Similar to this question: Dealing with "null" values in python Altair tooltip's text, I have missing values in some field of columns that I use for a tooltip. But rather than changing ...
roble's user avatar
  • 304
0 votes
0 answers
13 views

How to hide legend entries from unselected series in altair?

I have two linked charts with a selection enabled on the left (points) that controls which series are draw on the right (linespoints). I would like to display only the legend entries from the selected ...
kpoint's user avatar
  • 1
0 votes
0 answers
14 views

How to make timeseries from pandas dataframe in Altair

I've got a dataset from here. https://www.dropbox.com/scl/fi/l7toin3wj6s6iwd3s6r8y/local_obesity.csv?rlkey=lk8ipdlhgdfijscq429pksktk&dl=0 I wanted to create an interactive visualisation using ...
elksie5000's user avatar
  • 7,064
0 votes
0 answers
17 views

How to select multi items from a single Altair dropdown menu?

I want to select multiple items from a dropdown menu that I created as below: clients_dropdown=alt.binding_select(options=clients, name=‘Exclude Client(s)’) clients_selector=alt.selection_single(...
ibuli23's user avatar
0 votes
0 answers
25 views

How use drop-down filters in Altair and redraw plot on selection

I have some long-form data in a pandas dataframe that looks like this: region result year variable value 0 County Durham North East 2014 admissions_total 2240 1 Darlington ...
elksie5000's user avatar
  • 7,064
0 votes
0 answers
19 views

How to create an Altair plot based on two filters

This is complicated. I'm trying to create a visualisation about obesity-related hospital admissions in the UK over time. I've converted it into long form as that appeared to be the best way of simply ...
elksie5000's user avatar
  • 7,064
0 votes
0 answers
12 views

How to extract a list-like value from a dropdown menu selection using altair

My partial code below is to try to exclude clients selected thru using dropdown menu. However, I can't get list like object from selection. def cal_h(df, selected_clients=None): if ...
ibuli23's user avatar
1 vote
1 answer
20 views

How to stack charts in Altair

I have a series of charts that I want to put together in Altair to create a dashboard. The first is national stats Top left. Let's call it top_left The second is at regional level. I want this ...
elksie5000's user avatar
  • 7,064
0 votes
0 answers
15 views

How to Show Specific Days on Altair Chart time axis

I am plotting data of stock price over time using altair, my dataframe doesn't contain data for weekend days, and this appears as gaps on chart. How can I make the Chart plot only Monday to Friday for ...
Mohamed Fouad's user avatar
1 vote
1 answer
55 views

How to use altair scale(zero=False)?

When executing the following code I would expect the graph to not include zero, but instead start somewhere around the minimum point in the data shown on the y-axis. import pandas as pd import altair ...
Mariano Kamp's user avatar
  • 2,366
0 votes
0 answers
32 views

Stacked barplot in streamlit

df = pd.DataFrame({'Category': {0: 'Category 1', 1: 'Category 1', 2: 'Category 1', 3: 'Category 1', 4: 'Category 1', 5: 'Category 1', 6: 'Category 1', 7: 'Category 2', 8: 'Category 2', 9: '...
Chris's user avatar
  • 2,009
0 votes
1 answer
22 views

Scaling values in Altair to fit on layer?

I have a graph of stock prices and a layer with Earnings Expected and Earnings Actual. The issue is the stock price can be $50 or $100 where the earnings values are usually within a couple dollars ...
engineer-x's user avatar
  • 2,227
0 votes
0 answers
25 views

altair: empty plot in facetted layout with grid lines

I have a plot similar to this one with this toy data import pandas as pd import altair as alt df = pd.DataFrame( { "id": [1, 2, 3, 4, 5], "sex": ["M",...
Revan's user avatar
  • 2,082
2 votes
0 answers
23 views

altair: boxplot with one observation

I am working on a dashboard for a project where I am receiving updated data on a daily basis (meaning that some of the dataframes are only poorly populated). I would like to visualize the different ...
Revan's user avatar
  • 2,082
2 votes
2 answers
42 views

Altair visualization with mark image breaks using certain images

I've been practicing my usage of Altair and recently decided to create a dashboard to analyze Magic The Gathering decks, using Scryfall to obtain card information. One of the visualizations in my ...
Galen's user avatar
  • 31
1 vote
2 answers
44 views

How to draw bar charts with labels

I'm trying to execute the code from official documentation (Bar Chart with Labels) and use exactly the same lines: import altair as alt from vega_datasets import data source = data.wheat() base = ...
JaSON's user avatar
  • 4,843
0 votes
0 answers
14 views

Can I append to altair Tooltips instead of creating from scratch?

I've been creating tooltips in altair by using the tooltip encoding. Is there a way I can 'add to' the default tooltip (that contains the x, y, color, facet values etc), instead of having to type out ...
selwyth's user avatar
  • 2,417
0 votes
0 answers
19 views

Having trouble creating Histogram from data off a CSV, object has no attribute or 'Series' object is not callable?

So I'm just trying to created a simple histogram of the masses found in my data, I followed this simple example: # importing libraries import altair as alt from vega_datasets import data # ...
chris trejo's user avatar
0 votes
0 answers
22 views

Interactive horizontal rules for vega altair

I want to plot upper and lower limits for a number of metrics over uids. These upper and lower limits are expectations and are single value for each metrics. I want to make it interactive such that ...
Daniel Cho's user avatar
3 votes
1 answer
72 views

Wrap legend text in altair

I have the following example where I'm trying to plot 4 points. When I wrap the text for the point legend labels the result is only 1 point for each category (2 points total). Any help figuring out ...
Stephen Williams's user avatar
0 votes
0 answers
13 views

How do I combine a dataset with worldmap

I have a CSV File which i defined it as "Forest". It contains data about Deforestation from 1990 until 2015. I wanted to it to a world map, which shows every single country of the data set. ...
Schmarti's user avatar
0 votes
0 answers
44 views

Add legend to alt.chart

I am unable to add legend to my layered chart. Please advise how to add legend to this one. a1 = alt.Chart(queried_data2).mark_line(strokeWidth=2,color="#FFAA00").encode( x=alt.X('MONTH:...
VSN's user avatar
  • 25
0 votes
0 answers
50 views

Using Altair to plot from one dataframe referencing multiple CSV url data sources

For a dataset containing spectra as individual csv files, I am making a viewer as a streamlit app, using altair (+ potentially VegaFusion if it makes sense) for plotting. I have pandas dataframe where ...
roble's user avatar
  • 304
0 votes
0 answers
67 views

Including a color scheme when passing color as a dict Altair

How do I add a color scheme to the first condition (instead of 'red')? The code below works as intended. I have had to write in dictionary form for it to work: cutoff = 10 color_data = 'RME' #(RME is ...
hello_planet's user avatar
0 votes
0 answers
13 views

How to get rid of the rhombus-like shapes from the altair steamgraph?

I have an altair graph which mostly works well, but based on the data can end up being distorted. One example is: How to explain that, and how to fix it? Here is the source code import altair as alt ...
kboom's user avatar
  • 2,289
0 votes
0 answers
19 views

Disable clearing selection in vega-lite/altair geoshape

I want to be able to select a item on a map and use that selection in other graphs and always have exactly one item selected. I thought that setting toggle and clear to False should assure this, but ...
Bert Coerver's user avatar
0 votes
0 answers
29 views

altair tooltip layered chart not showing on mac screen

The following code works as expected except on the native macbook pro screen the tooltips wont reveal the data. If I move the chrome tab to either of my secondary monitors the tooltips display ...
phidelity's user avatar
0 votes
0 answers
33 views

Filter Transform on layered Altair charts error

I want to use multiple drop-down to look at various days of prediction intervals against the actual price of something. I have created the drop-downs and it works individually. However, when I try to ...
GN_nick's user avatar
1 vote
0 answers
33 views

How to set an initial calculated selection interval in Altair

I am trying to set a calculated initial selection interval in an Altair-viz graph. There are a lot of examples of hardcoding the interval but I cannot find a way to for example choose the last year to ...
timthoe's user avatar
  • 75
2 votes
1 answer
24 views

Altair log position of tooltip on click to file

I aim to keep a log (log file or dataframe) of all the countries a user has clicked on. I am trying to log the id of the tooltip on click, but do not know how I can extract any values. I'd be happy ...
a-doering's user avatar
  • 1,149
0 votes
1 answer
29 views

How to make an interactive plot in pandas and altair

Simple imports of pandas and altair. Why the shape of the plot when one datapoint by each row? #"https://www.who.int/data/gho/data/indicators/indicator-details/GHO/mean-bmi-(kg-m-)-(crude-...
elksie5000's user avatar
  • 7,064
0 votes
0 answers
62 views

Why zig-zag in time series plot visualisation in Altair

Simple imports of pandas and altair. #"https://www.who.int/data/gho/data/indicators/indicator-details/GHO/mean-bmi-(kg-m-)-(crude-estimate)") df = pd.read_csv("obesity_WHO.csv") ...
elksie5000's user avatar
  • 7,064
0 votes
1 answer
39 views

How to reduce rows in Altair plots using groupby in pandas

Okay, I have a dataset. import pandas as pd import altair as alt #"https://www.who.int/data/gho/data/indicators/indicator-details/GHO/mean-bmi-(kg-m-)-(crude-estimate)") df = pd....
elksie5000's user avatar
  • 7,064
0 votes
1 answer
57 views

specified without a type

I tried to filter some datas from a csv file. It worked fine. Now i wanted to do some graphs with altair. I imported it already. Forest=pd.read_csv("AnnualChangeForest.csv", sep=',') Forest ...
Schmarti's user avatar

1
2 3 4 5
26