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.
altair
1,375
questions
0
votes
0
answers
13
views
How to control width of .hconcat subplot
I am trying to concatenate two graphs, with the one on the beign dependent on the selection made on the graph on the left. The problem is that the right graph is a bar type, and depending on the ...
2
votes
1
answer
34
views
altair: how to make an interactive plot with a regression line on top of it?
I'm trying to make an interactive plot that has a regression line on top of it. Here is the plot in the Vega editor and here is a gist of the Altair source (MRE). This is heavily influenced by this ...
0
votes
0
answers
17
views
log-log regression, possible in Altair?
Is there any way to do a log-log regression (both x and y axes are on a logarithmic scale)? Linear-linear, linear-log, log-linear all seem straightforward.
0
votes
1
answer
62
views
Using a list of colors for a bar chart in Altair
I am trying to provide a list of colors to bind to the bar marks in Altair, similar to how matplotlib's pyplot.bar(color=list_of_colors) can specify the color for each individual bar, like in the ...
3
votes
1
answer
56
views
Altair Barchart is blank, matplotlib equivalent shows correct visualization
I have been using altair for a time and this is the first time that I have experienced this issue, I have this simple code:
import pandas as pd
import altair as alt
# extract data into a nested list
...
0
votes
2
answers
36
views
Remove gap between two graphs with shared axis
Objective
I want to generate a 'double ended' barchart, showing gained points (of some metric) vis-a-vis missed points, something like this:
Result so far
I managed to do this
import altair as alt
...
1
vote
2
answers
43
views
Altair chart legend for subset of data
As an exercise for learning more advanced altair, I'm trying to generate a simplified version of this chart: https://climatereanalyzer.org/clim/t2_daily/?dm_id=world.
To simplify, I'm using gray for ...
1
vote
1
answer
21
views
Inconsistent graphs with Altair despite same package version
I am working on creating graphs using Altair in different environments with different package sets. Despite ensuring the Altair version is consistent across these environments, I am observing ...
1
vote
0
answers
36
views
Python: ImportError: DLL load failed while importing lib: The specified procedure could not be found
python programming newbie here. I was trying to create a simple histogram with altair using the following code. The dataset is large, around 1,000 rows.
count_chart = alt.Chart(df).mark_bar().encode(
...
0
votes
0
answers
36
views
Wrong rectangle width in altair chart for pandas dataframe
I have pandas dataframe which stores currency rate for given day.
print(df[['Date', 'Currency', 'Rate']].head())
Date Currency Rate
18 2023-12-01 AUD 1.64655
19 2023-12-01 BRL ...
1
vote
1
answer
45
views
Altair: add a line in a grouped bar chart
I have this data that I want to plot. In column 'IPVA' there are [0, 1, 2] as possible values, where 1 and 0 are the data that I want to plot as a grouped bar chart, and the 2 is data that I want to ...
2
votes
1
answer
33
views
Altair not displaying data when changing option on dropdown selector
I want to display counts of a certain feature according to the year with an Altair Chart and I want to do it by selecting year as an option of a dropdown selector. It works fine with the 'None' option ...
0
votes
1
answer
34
views
How to phrase selection_point in altair to do a selection_multi?
Altair now warns that selection_multi is deprecated and tells to use selection_point instead. I tried to replace it with same functionality with no success. How should I do it?
1
vote
1
answer
33
views
Clamping Daily Temperature Plot with Altair on Colab
I'm trying to use altair to recreate the world temperature plot from Climate Reanalyzer: https://climatereanalyzer.org/clim/t2_daily/?dm_id=world. The data is pretty easy to load:
import pandas as pd
...
1
vote
1
answer
23
views
Altair Show Axis Tick Labels As Percentage Point
I would like to format axis tick labels as percentage point.
import altair as alt
from vega_datasets import data
source = data.jobs.url
alt.Chart(source).mark_line().encode(
alt.X('year:O'),
...
1
vote
1
answer
28
views
Altair chart empty by dropdown when other chart is displayed
I want to have two different charts, where in the first I can choose an artist in a legend and in the second chart I want to have a dropdown, that filters a year. In my database I have artists, sales ...
1
vote
1
answer
37
views
Remove gaps with xOffset
Is there a way to not have gaps at non-existing data when using x/yOffset? In the example below, category B only has 1 group (x) and I would like that bar to be centered at the B-tick.
source = pd....
1
vote
1
answer
27
views
Bars not extending the full size in Vega/Altair plot
I'm trying to plot a histogram from pre-binned data using Vega-lite (Actually, Altair in Python, but I got the issue when using Vega directly as well). My dataset contains the following fields:
bin: ...
1
vote
0
answers
44
views
Display only the first value of the dropdown menu. on Altair Chart
I would like my chart to show only the first value of the dropdown menu (the red dots representing "USA" in my case), instead of displaying all of the countries prior to any filtering. I ...
0
votes
1
answer
33
views
Reorder a stacked barplot in altair
So I am making an interactive plot (which is why I'm using altair) and I want to reorder the stacks within each bar to match the legend. I've tried reodering the df, I've tried using the 'sort' ...
3
votes
1
answer
69
views
Altair - Boxplot border to be set black and median line red
I want to set a black border color to the boxplot of a altair graph, i try to add stroke parameter to black on the encoding chanel but this overrided my red median line to black.
This is the code I am ...
0
votes
0
answers
57
views
Altair use multiple selections in multi-layer chart
I would like to have multiple selections in a multi-layer chart. One selection should highlight the closest line and the other should highlight the point on each line closest to the current x position ...
0
votes
0
answers
27
views
Linking Geospatial data to a bar chart
I am attemtping to link two graphs together, a geospatial graph of Philladelphia outlining its districts along with a bar chart that shows the amount of complaints against police per district. This is ...
2
votes
0
answers
24
views
Use value of alt.selection_point as sort field
I have the following facet chart where the order of the facet panels is determined by the column foo. I would like to add a drop-down box where I can select to dynamically update the sort order of the ...
1
vote
1
answer
27
views
Altair Graph in Notebook
When I tried to draw the graph of USGS earthquakes using Altair, it always gives me blank graph. Here are my codes
current_time = datetime.utcnow().strftime('%Y-%m-%dT%H:%M:%S')
api_url = "https:...
2
votes
1
answer
124
views
Building plots with plotnine and Python
I am looking for a way that I can modify plots by adding to an existing plot object. For example, I want to add annotations at particular dates in a work plot, but want a standard way of building the ...
2
votes
1
answer
52
views
Concatenate two geoshape charts in Altair / Vega-Lite with independent axis?
I am trying to plot two separate geoshape charts and concatenate them together. Below is a MWE of what I am trying to do:
import altair as alt
from vega_datasets import data
import geopandas as gpd
...
1
vote
0
answers
26
views
Mark_text Altair doesn't working with multiple data at same month
I'm writing a code in python with altair and streamlit.
I wrote all the code and have almost everything working, but im having a issue with multiple data sum() mark_text on same month.
Example:
DT ...
1
vote
1
answer
22
views
Altair Chart selected data to graph
I have a dataframe with multiple type-value pairs. Lets say it is:
dt = pd.DataFrame({'date': ['2022', '2023', '2024'], type':['t1', 't2', 't3'], 'value': [1, 2, 3]})
of cause, with much more data ...
0
votes
1
answer
25
views
Altair - Display multiple names in a tooltip from overlapping points
I am working on a visualization to show when pokemon become available in Pokemon Emerald. After scraping data, I am now beating my head against the wall on how to make multiple names show up when ...
0
votes
1
answer
97
views
Altair choropleth not rendering in streamlit app on Snowflake and color coding problem
I am trying to make a choropleth map in a streamlit app on Snowflake.
Outside of snowflake, I can use the following code to render a map where just one county in Alabama is color coded.
import ...
0
votes
0
answers
24
views
Altair - display lines on a mouseover
I'm trying to display lines (link between centroïd and points) on a map only if I pass my mouse over. But I still don't get why it doesn't work.
Do you know any other function with Altair to do it ...
0
votes
0
answers
34
views
How to fix altair transform_filter()?
I'm trying to create a choropleth map of the US displaying the percentages of the population with different disabilities. However, using the drop-down selection tool bar makes the data/color of the ...
1
vote
0
answers
60
views
Select zoom axis per drop-down menu
I have a scatterplot in which I want to zoom on either the y axis, the x axis or both. I would like the user to select this behavior via a dropdown menu.The standard setting would be both like ....
0
votes
0
answers
28
views
Altair sorting not working properly on faceted chart
I have some faceted bar graphs displaying the amounts of different colors in different paintings.
base = alt.Chart(df).mark_bar().encode(
x=alt.X(
'color',
title='',
...
2
votes
1
answer
140
views
Efficient interactive plots of large datasets -- which framework to use?
I have a moderate-to-large dataset of ~500k points which I would to visualize with an interactive 2d scatterplot (ideally through a web-app).
Usually am quite fond of the altair package (Python) for ...
1
vote
1
answer
58
views
Table with multi-line strings in Altair
I was trying to write a table with some entries being multi-line using altair, but seem to get into trouble with fixing line spacing. For example:
text_df = pd.DataFrame({"a":["very ...
0
votes
0
answers
49
views
Convert seconds to days, hours, etc on axis labels
I am trying to plot a chart which needs to have duration times in terms of "days, hours, minutes" on the Y axis and just dates on the X axis. I can do this easily if the duration is ...
1
vote
2
answers
89
views
Custom ordering in a grouped bar chart not applied in Altair?
I am trying to achieve a custom sort order for a series of categories in a grouped bar chart.
An issue on GitHub from a few years ago suggests how to do this: by supplying a list with the custom sort ...
1
vote
0
answers
25
views
How modify altair multiple tooltip by y values
I'm looking to customize the tooltips in my Altair chart. I have two specific requirements:
Order the tooltip lines based on the value of the element, and hide certain tooltip lines depending on their ...
1
vote
1
answer
44
views
Consolidating multiple color legends in layered and faceted Altair plots
In Altair, if I layer two plots with color scales on different attributes and then also facet them I end up with multiple copies of the color legend. If there's just one color scale it correctly ...
1
vote
1
answer
36
views
Overlaid boundary and point Altair plots are not aligning
I've got a layer map plot in Altair of London that I was struggling to flip - Solving upside plot and projection problems in Geopandas and Altair
However, a more troubling problem is that I've got a ...
0
votes
1
answer
61
views
Dynamic label with number of points in scatterplot based on transform selection in Altair?
tl;dr: is there a way to get a dynamic count of points in filtered plots in Altair?
In the 'filtering by selection' example for Altair, it is possible to update a scatterplot based on a selection in ...
1
vote
2
answers
84
views
Solving upside plot and projection problems in Geopandas and Altair
I'm trying to plot a multi-layered map of London using some data from the ONS.
import geopandas as gpd
from shapely import wkt
# Convert the 'geometry' column to shapely geometry objects
...
1
vote
1
answer
33
views
Altair choropleth map doesn't display
I'm trying to create a choropleth from some Kaggle data: https://www.kaggle.com/datasets/jessemostipak/hotel-booking-demand but something isn't working.
import pandas as pd
import altair as alt
from ...
1
vote
0
answers
39
views
chart objects not showing on the chart using selection containing fields with converted columns from datetime data
I am using Altair to create visualisations based on a local csv file about WW1 bombing incidents.nI tried to make 2 charts: one shows all incidents in the same month, one shows all incidents in the ...
0
votes
0
answers
57
views
Get interval selection for a Vega-Altair plot published in streamlit
How can I get the selected datapoints for a Vega-Altair plot publihsed using Streamlit?
I am defining the box selection for selecting datapoints, and it works well. However i am unable to get the ...
1
vote
1
answer
54
views
Calculate new series based on data in filtered altair chart
I have a timeseries dataframe which I'm using to create a heatmap (showing the difference on the most recent observation between the two relevant values) and two line charts -- one showing the series ...
1
vote
0
answers
104
views
How to specify different colors for column labels in altair
Is there a way to specify different colors for column labels with python altair? Take the grouped bar chart example where bars are grouped using the column encode option. I would like to specify ...
1
vote
0
answers
26
views
How to add two side slide button to a line chart based on the year using Altair
i have a line chart that has date as X axis. i want to filter this with a double (two) sided slide button for filtering proposes. So i want to be able to filter the data from starting and end date of ...