altair

Add legend to line & bars to Altair chart without using size/color

自作多情 提交于 2021-02-10 14:51:44
问题 I'm using Altair to create a chart with multiple lines each of which has multiple bands (representing different CI) & I'm struggling to understand how I can add a legend. For example, in this considerably simpler example: import altair as alt import pandas as pd df = pd.DataFrame(data={'col1': [1, 2,4,5,6], 'col2': [3, 4,7,4,4], 'col3': [1.5, 2.6,4.6,5.6,6.6], 'col4': [3.6, 4.6,7.6,4.6,4.4],'col5': [1.9, 2.9,4.9,5.9,6.9], 'col4': [3.9, 4.9,7.9,4.9,4.9]}) line = alt.Chart(df).mark_line(color=

How to show Vega visualizations in Google Colab

扶醉桌前 提交于 2021-02-10 05:33:08
问题 I can use Altair to show Vega-Lite visualizations in Google Colab. But is there a way to show plain Vega visualizations? I tried ipyvega in Google Colab. But when I run their example in Google Colab, then nothing shows up, and there is no error. 回答1: You can display a vega chart in Colab using the altair.vega.Vega class, once you have enabled the Colab renderer. Here is an example: from urllib import request import json with request.urlopen("https://vega.github.io/vega/examples/bar-chart.vg

How to set locale in Altair?

会有一股神秘感。 提交于 2021-02-08 17:23:22
问题 I'm successfully creating and rendering a chart in Altair with a currency prefix ($), but I need this to be set to GBP (£). I know that there's a Vega-lite formatLocale which can be set, but I can't work out how to pass the value I need to Vega-lite. I can't find anything on locale in the Altair docs. def chart_tenders_monthly_value(dataframe=None): chart = ( alt.Chart(dataframe, title="Tender value") .mark_bar() .encode( alt.X( "yearmonth(date):O", axis=alt.Axis(title="Month") ), alt.Y(

Altair adding date slider for interactive scatter chart pot

和自甴很熟 提交于 2021-02-08 05:54:06
问题 Has anyone tried using date as a slider for Altair interactive scatter plots? I'm trying to reproduce a similar plot to the gapminder scatter: 1) Instead of a year filter I'm trying to use a date e.g. '2020-01-05' and having the follow error: altair.vegalite.v4.schema.core.BindRange->max, validating 'type' '2020-05-17T00:00:00' is not of type 'number' 2) When I try to parse it as an int, nothing shows up in the plot 3) Examples of using the Year slider: https://www.datacamp.com/community

Altair - Areaplot with different colours for negative and positive

独自空忆成欢 提交于 2021-01-29 10:49:40
问题 I have a column in my pandas DataFrames with positive and negative values, I need to make an area graph with different colours for positive and negative y axis. So far, I am not able to do that with alt.condition brush = alt.selection(type='interval', encodings=['x']) upper = alt.Chart(yData['plotY'].fillna(0).reset_index()[24000:26000], title = '_name').mark_area().encode(x = alt.X('{0}:T'.format(yData['plotY'].index.name), scale = alt.Scale(domain=brush)), y = 'plotY', # color=alt.condition

Altair limit number of bars in facet chart

大城市里の小女人 提交于 2021-01-28 06:16:54
问题 Suppose that I have a pandas dataframe like this one: label counts group 4 4 8 1 5 5 7 1 6 6 6 1 7 7 5 1 0 0 4 2 1 1 3 2 2 2 2 2 3 3 1 2 I want to make a bar chart with altair, where the height of the bars is counts, and the label is the label. I want to add a facet by the column group . How do I limit the number of bars to be shown, if I want the top 3 counts for each sub-chart? Hopefully I'd like to do this without performing operations in pandas on the dataframe, and instead do them with

How to render Altair / Vega in a PyQt widget

不羁的心 提交于 2021-01-27 22:07:18
问题 Is it possible to have Altair or Vega(-Lite) render to a PyQt widget, similar to Matplotlib supporting multiple backends? I know I can use a Qt WebView widget to render a web page with Vega-embed, but I want to prevent the overhead of having to serve this, even if locally. 回答1: The best option to visualize a plot with Altair is to use QWebEngineView since altair what is to create javascript code based on the instructions you set. IMHO the best solution is to obtain the html of the chart and

On an Altair plot, can you change the location that a selection (e.g. dropdown, radio button) is displayed?

不问归期 提交于 2021-01-27 20:11:23
问题 Plotting in Python using Altair: I have 2 charts plotted side-by-side and the right-hand plot includes a drop-down selection menu. By default, the drop-down menu displays on the bottom left of the plot. I would like to move the menu underneath the right-hand plot that it is linked to. I don't see anything in the documentation for selection_single or add_selection that relates to the location of the menu. I'm using the | method to concatenate the plots horizontally. Simplified example: Code to

Sorting based on the alt.Color field in Altair

做~自己de王妃 提交于 2021-01-27 19:50:44
问题 I am attempting to sort a horizontal barchart based on the group to which it belongs. I have included the dataframe, code that I thought would get me to group-wise sorting, and image. The chart is currently sorted according to the species column in alphabetical order, but I would like it sorted by the group so that all "bads" are together, similarly, all "goods" are together. Ideally, I would like to take it one step further so that the goods and bads are subsequently sorted by value of 'LDA

Altair Ridgeline doesn't create a plot with nominal groups

徘徊边缘 提交于 2021-01-27 17:30:44
问题 I try to create a Ridgeline plot in altair. Let's assume my dataframe consists of str and float columns: a object b float64 dtype: object with values like a b 0 25 2303.0 1 29 2676.0 2 18 2983.0 3 16 1489.0 4 21 3468.0 I used code from Altair gallery to create my chart: https://altair-viz.github.io/gallery/ridgeline_plot.html. My code with changed data and column names: import pandas as np import numpy as np source = pd.DataFrame(columns=list('ab')) source['a'] = np.random.randint(0,17,size