profile
viewpoint
Jake Vanderplas jakevdp Google Seattle WA http://www.vanderplas.com Python, Astronomy, Data Science

altair-viz/altair 4866

Declarative statistical visualization library for Python

altair-viz/pdvega 330

Interactive plotting for Pandas using Vega-Lite

altair-viz/altair-tutorial 234

Notebooks for the Altair tutorial

davidwhogg/MagicCube 174

don't ask

jakevdp/2013_fall_ASTR599 128

Content for my Astronomy 599 Course: Intro to scientific computing in Python

altair-viz/altair_widgets 102

Interactive data exploration with Altair

altair-viz/vega_datasets 81

A Python package for online & offline access to vega datasets

altair-viz/altair_pandas 68

Altair backend for pandas plotting

jakevdp/2014_fall_ASTR599 66

Content for my Astronomy 599 / Applied Math 500 Course: Intro to scientific computing in Python

altair-viz/altair-transform 41

Evaluation of Vega-Lite transforms in Python

issue commentaltair-viz/altair_saver

Connection refused error

Oh, maybe one guess: does your chart use data from an external URL?

thomasjhuang

comment created time in 11 hours

issue commentaltair-viz/altair_saver

Connection refused error

Thanks for the report. I can't reproduce this and I don't have any guesses as to what may be causing it. Please let me know if you are able to debug the issue.

thomasjhuang

comment created time in 11 hours

issue commentaltair-viz/altair

conditional formatting mark_text based on variable?

The relevant issue to add your +1 is here: https://github.com/vega/vega-lite/issues/4703

parodayco

comment created time in a day

issue commentaltair-viz/altair

conditional formatting mark_text based on variable?

Yes, you can conditionally encode the color, because the color is an encoding channel. You cannot conditionally encode offset, because offset is not (yet) an encoding channel.

parodayco

comment created time in a day

issue commentaltair-viz/altair

Altair Plots blocked by the Save Bubble

Have you tried closing all notebook tabs, closing the browser window, re-opening Jupyterlab, and then creating a chart in a new notebook? (Unfortunately, the way JupyterLab is architected, that's the only way to ensure that your CSS is clean).

MarcoRSousa

comment created time in a day

issue commentaltair-viz/altair

Altair Plots blocked by the Save Bubble

If you are able to figure out what extension or package is causing this (and what CSS attribute it's adding to cause the issue), that would be really helpful. I've still not seen this issue myself, and nobody who has reported it has been able to provide those details.

MarcoRSousa

comment created time in a day

issue commentaltair-viz/altair

invisible symbol in legend for mark_trail

This is a bug in Vega-Lite that was recently fixed: https://github.com/vega/vega-lite/issues/5879

The fix should make it into the next Altair release.

YuliaGazizova

comment created time in a day

issue commentaltair-viz/altair

conditional formatting mark_text based on variable?

No, unfortunately the only thing that can depend on conditions are encodings, not mark properties. I know the Vega-Lite team has been thinking about ways to relax this restriction, so you might inquire there.

parodayco

comment created time in 2 days

PR merged altair-viz/altair

DOC: Scale resolve edits

Add the dual y axis example to the scale resolve user guide

+63 -1

2 comments

1 changed file

eitanlees

pr closed time in 2 days

push eventaltair-viz/altair

Eitan Lees

commit sha 4b0173afdf8842fc1e4671bfa333de50ebb16f99

DOC: add dual axis details to scale resolve page

view details

Eitan Lees

commit sha 24f90394dce3edf29b3be05fb58ece8b015d34a1

DOC: fix link in scale resolve guide

view details

Eitan Lees

commit sha f25199cac2155d7a8d22b1ecfa54a194ae96e3e5

DOC: add transform links to scale resolve user guide

view details

Eitan Lees

commit sha 2fc1d5f3d68b4427733f55e9875b3c915be5b1ea

DOC: fix typo in scale resolve user guide

view details

Jake Vanderplas

commit sha e2eb5224996bcb4646387dea955ceeed80495551

Merge pull request #1975 from eitanlees/scale-resolve-edits DOC: Scale resolve edits

view details

push time in 2 days

pull request commentaltair-viz/altair

DOC: Scale resolve edits

Looks good, thanks!

eitanlees

comment created time in 2 days

Pull request review commentaltair-viz/altair

DOC: Scale resolve edits

 This default can be changed by setting the scale resolution for the color to        base.encode(color='Cylinders:O')    ).resolve_scale(        color='independent'-   )\ No newline at end of file+   )++Dual Y Axis+~~~~~~~~~~~++A common technique for combining chart containing different measures is using a+dual y axis. There are two strategies to achieve this result using altair. The+first is to manually specify the mark color and associated axis title color of+each layer. ++.. altair-plot::++    import altair as alt+    from vega_datasets import data++    source = data.cars()++    base = alt.Chart(source).encode(+            alt.X('year(Year):T')+    )++    line_A = base.mark_line(color='#5276A7').encode(+        alt.Y('average(Horsepower):Q', axis=alt.Axis(titleColor='#5276A7'))+    )++    line_B = base.mark_line(color='#F18727').encode(+        alt.Y('average(Miles_per_Gallon):Q', axis=alt.Axis(titleColor='#F18727'))+    )++    alt.layer(line_A, line_B).resolve_scale(y='independent')++In this case the axis colors act as a pseudo-legend. Alternatively if you want+a legend some transformations must be applied. Legends are only created in+Vega-Lite to represent an encoding.

It would be useful to link to the fold and filter transform docs here: :ref:`user-guide-filter-transform` and :ref:`user-guide-fold-transform`

eitanlees

comment created time in 2 days

push eventaltair-viz/altair

Eitan Lees

commit sha 31bd8860036f778252921f72450f9fe5c346c145

FIX: change datum repr to fix doc build

view details

Jake Vanderplas

commit sha 9d20350c2c427655de2485a95b6e9d89cbde92fd

Merge pull request #1974 from eitanlees/datum-repr FIX: change datum repr to fix doc build

view details

push time in 2 days

PR merged altair-viz/altair

FIX: change datum repr to fix doc build

discussed in https://github.com/altair-viz/altair/issues/1972

+1 -1

1 comment

1 changed file

eitanlees

pr closed time in 2 days

pull request commentaltair-viz/altair

FIX: change datum repr to fix doc build

Looks good, thanks!

eitanlees

comment created time in 2 days

issue commentaltair-viz/altair

DOC: Compilation Errors

That said, now that I think about it, it is valid to use datum by itself in a spec. Here's an example:

import altair as alt
import pandas as pd

df = pd.DataFrame({'x': range(5)})


alt.Chart(df).transform_calculate(
    datum_ref='datum',
    z='datum.datum_ref.x'
).mark_point().encode(
    x='z:O'
)

visualization - 2020-02-17T065554 698

I'm not sure why you'd ever want to do it, but experience has shown that Altair users figure out ways to use the grammar that we'd never anticipate :smile:

I think it's probably best to make the change you mention above, to err away from being overly restrictive.

eitanlees

comment created time in 2 days

issue commentaltair-viz/altair

DOC: Compilation Errors

That solves the docs problem, but if users leave a stray alt.datum within their chart specification, it will replace an easier-to-debug python error with a more-difficult-to-debug javascript error. I'm not certain raising a ValueError on repr is the best solution to this, however...

eitanlees

comment created time in 2 days

issue closedaltair-viz/altair

Are there any known bugs with altair.Column(sort)?

Code

top5_leagues = bvb[bvb['league'].isin(['LaLiga', 'Premier League', 'Bundesliga', 'Serie A', 'Ligue 1'])]

alt.Chart(top5_leagues).mark_bar().encode(
        x='trans_type:N',
        y='sum(fee):Q',
        column=alt.Column('league:N', sort=['LaLiga', 'Premier League', 'Bundesliga', 'Serie A', 'Ligue 1'])
    )

Output visualization-2

The code is the same as in the example from the docs (which works fine in my environment).

Example from docs

alt.Chart(source).transform_filter(
    alt.datum.symbol != 'GOOG'
).mark_area().encode(
    x='date:T',
    y='price:Q',
    color='symbol:N',
    row=alt.Row('symbol:N', sort=['MSFT', 'AAPL', 'IBM', 'AMZN'])
).properties(height=50, width=400)

I have restarted the kernel and double-checked all expressions but no success so far. Changing the order of the strings in the array also had no effect.

closed time in 2 days

jan-scorl

issue commentaltair-viz/altair

Are there any known bugs with altair.Column(sort)?

Yes, this is a known bug; see https://github.com/altair-viz/altair/issues/1683 and https://github.com/vega/vega-lite/issues/5366

jan-scorl

comment created time in 2 days

IssuesEvent

issue closedaltair-viz/altair

DOC: Compilation Errors

I am having trouble compiling the docs again.

There seems to be an issue with with One Dot Per Zipcode example.

In the altair/doc/ directory I ran

make clean-all
make html

Everything was chugging along but then crashed with the following output

writing output... [ 12%] gallery/normed_parallel_coordinates
Exception occurred:
  File "/Users/eitanlees/sandbox/open_source/altair-viz/altair/altair/expr/core.py", line 7, in __repr__
    raise ValueError("must use datum.attribute")
ValueError: must use datum.attribute
The full traceback has been saved in /var/folders/dh/ts6jzzjj7pn1_76vh_6vnn6c0000gn/T/sphinx-err-e2vhz5gm.log, if you want to report the issue to the developers.
Please also report this if it was a user error, so that a better error message can be provided next time.
A bug report can be filed in the tracker at <https://github.com/sphinx-doc/sphinx/issues>. Thanks!
make: *** [html] Error 2

Following the link to the full traceback I found

Traceback (most recent call last):
  File "/Users/eitanlees/miniconda3/lib/python3.7/site-packages/sphinx/cmd/build.py", line 276, in build_main
    app.build(args.force_all, filenames)
  File "/Users/eitanlees/miniconda3/lib/python3.7/site-packages/sphinx/application.py", line 349, in build
    self.builder.build_update()
  File "/Users/eitanlees/miniconda3/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 299, in build_update
    len(to_build))
  File "/Users/eitanlees/miniconda3/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 361, in build
    self.write(docnames, list(updated_docnames), method)
  File "/Users/eitanlees/miniconda3/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 535, in write
    self._write_serial(sorted(docnames))
  File "/Users/eitanlees/miniconda3/lib/python3.7/site-packages/sphinx/builders/__init__.py", line 545, in _write_serial
    self.write_doc(docname, doctree)
  File "/Users/eitanlees/miniconda3/lib/python3.7/site-packages/sphinx/builders/html.py", line 612, in write_doc
    self.docwriter.write(doctree, destination)
  File "/Users/eitanlees/miniconda3/lib/python3.7/site-packages/docutils/writers/__init__.py", line 78, in write
    self.translate()
  File "/Users/eitanlees/miniconda3/lib/python3.7/site-packages/sphinx/writers/html.py", line 58, in translate
    self.document.walkabout(visitor)
  File "/Users/eitanlees/miniconda3/lib/python3.7/site-packages/docutils/nodes.py", line 214, in walkabout
    if child.walkabout(visitor):
  File "/Users/eitanlees/miniconda3/lib/python3.7/site-packages/docutils/nodes.py", line 227, in walkabout
    visitor.dispatch_departure(self)
  File "/Users/eitanlees/miniconda3/lib/python3.7/site-packages/sphinx/util/docutils.py", line 501, in dispatch_departure
    (method.__name__, node))
  File "/Users/eitanlees/miniconda3/lib/python3.7/site-packages/docutils/nodes.py", line 586, in __unicode__
    ''.join([unicode(c) for c in self.children]),
  File "/Users/eitanlees/miniconda3/lib/python3.7/site-packages/docutils/nodes.py", line 586, in <listcomp>
    ''.join([unicode(c) for c in self.children]),
  File "/Users/eitanlees/miniconda3/lib/python3.7/site-packages/docutils/nodes.py", line 589, in __unicode__
    return self.emptytag()
  File "/Users/eitanlees/miniconda3/lib/python3.7/site-packages/docutils/nodes.py", line 618, in emptytag
    for n, v in self.attlist()])
  File "/Users/eitanlees/miniconda3/lib/python3.7/site-packages/docutils/nodes.py", line 618, in <listcomp>
    for n, v in self.attlist()])
  File "/Users/eitanlees/sandbox/open_source/altair-viz/altair/altair/expr/core.py", line 7, in __repr__
    raise ValueError("must use datum.attribute")
ValueError: must use datum.attribute

Not sure if it's something on my end, something with the example, or something with the sphinx extension that is causing the issue.

Can others compile the docs just fine?

closed time in 3 days

eitanlees

issue commentaltair-viz/altair

DOC: Compilation Errors

We could probably change the repr to "datum"

eitanlees

comment created time in 3 days

issue commentaltair-viz/altair

DOC: Compilation Errors

I've not had any problems compiling the docs. That error happens when the repr of alt.datum is computed. Maybe something changed in a recent sphinx release that caused it to compute the repr of objects it finds?

eitanlees

comment created time in 3 days

issue closedaltair-viz/altair

hconcat() throws an error when two charts use the same transform_filter

Running

chart1 = alt.Chart(
    bvb, 
    title={
        'text': "Chart 1",
        'subtitle': 'Excluding free agents'
    }).transform_filter(
    datum.fee > 0
).transform_fold(
    ['value', 'fee']
).mark_bar().encode(
    y='average(value):Q',
    x='key:O',
    color='key:N',
    column='trans_type'
)

chart2 = alt.Chart(
    bvb, 
    title={
        'text': "Chart 2",
        'subtitle': 'Excluding free agents'
    }).transform_filter(
    datum.fee > 0
).transform_fold(
    ['value', 'fee']
).mark_bar().encode(
    y='average(value):Q',
    x='key:O',
    color='key:N',
    column='trans_type'
)

alt.hconcat(chart1, chart2)

throws this error:

Javascript Error: Undefined data set name: "scale_concat_1_child_main"
This usually means there's a typo in your chart specification. See the javascript console for the full traceback.

Can get solved by making the criteria for transform_filter unique for each chart. Also happens with hconcat() when two out of three charts share the same transform_filter criteria.

closed time in 3 days

jan-scorl

issue commentaltair-viz/altair

hconcat() throws an error when two charts use the same transform_filter

Thanks – I believe this is a known Vega-Lite issue, but I can't find the reference right now.

jan-scorl

comment created time in 3 days

issue commentaltair-viz/altair

How can I style the tooltip when creating a custom theme?

There are no options within Altair to change tooltip styles. If you want more flexible tooltips, you can use vega-embed directly along with the vega-tooltip plugin. As far as I know, there is not any documentation or examples of doing this from Altair.

jan-scorl

comment created time in 5 days

issue commentaltair-viz/altair

Stroke width not consistent for bar chart with multiple bars overlaid

OK, in that case I'd probably use a filter transform rather than a conditional opacity. Then only the data you're interested in displaying will be shown in the chart:

chart_bar = alt.Chart(df_melt).mark_bar(filled=False, color='black', strokeWidth=0.3).encode(
    x='cat',
    detail='count()'
).transform_filter(
    'datum.condition == 1'
)

(chart_point + chart_bar).configure_scale(bandPaddingInner=0.5)

visualization - 2020-02-14T114412 224

kaisengit

comment created time in 5 days

issue commentaltair-viz/altair

Stroke width not consistent for bar chart with multiple bars overlaid

OK - you have multiple rows in the dataset associated with each bar. Do you want to hide the bar if all of the relevant conditions are False, or if any of the relevant conditions are false? Or maybe if the majority of the conditions are False?

The best way to express this in code depends on exactly what you want to do.

kaisengit

comment created time in 5 days

issue commentaltair-viz/altair

Stroke width not consistent for bar chart with multiple bars overlaid

It's not clear to me from your code what the desired outcome is. Maybe a filter transform rather than an opacity condition would do what you want?

kaisengit

comment created time in 5 days

issue commentaltair-viz/altair

Stroke width not consistent for bar chart with multiple bars overlaid

This is because you're plotting N identical bars on top of each other, and N is different for each column. In Altair, if you don't provide some sort of aggregate, the renderer will always draw a mark for every row in the dataset.

In your case, when you want to change the grouping of data without changing their visual attributes, you can use the detail encoding, which is designed for exactly this purpose:

chart_bar = alt.Chart(df_melt).mark_bar(filled=False, color='black', strokeWidth=0.3).encode(
    x='cat',
    detail='count()'
)

(chart_point + chart_bar).configure_scale(bandPaddingInner=0.5)

visualization - 2020-02-14T064448 590

kaisengit

comment created time in 5 days

issue commentaltair-viz/altair

Suggestion for syntax sugar for regression transform

In order to make approach 2 work, the transform_regression method would have to add both an aggregate transform and a regression transform to the chart, which might be somewhat confusing. The reason we support aggregate shorthands within encodings is because in the Vega-Lite grammar, aggregates can appear in encodings. That is not the case within the regression transform grammar.

jan-scorl

comment created time in 6 days

issue commentaltair-viz/altair_saver

Cant import

Yeah, sometimes package environments can become corrupted in ways that are difficult to debug. Glad you finally got it working!

ndharari

comment created time in 6 days

issue commentaltair-viz/altair_saver

Cant import

Can you post a sequence of commands that reproduces the issue in a clean conda environment?

ndharari

comment created time in 6 days

issue commentaltair-viz/altair_saver

Cant import

Very strange... portpicker is listed in the conda-forge recipe as well: https://github.com/conda-forge/altair_data_server-feedstock/blob/master/recipe/meta.yaml#L25

What happens if you run import portpicker directly?

ndharari

comment created time in 6 days

issue commentaltair-viz/altair_saver

Cant import

portpicker is specified in the requirements of altair_data_server, which is specified in the requirements of altair_saver. If you installed altair_saver and don't have portpicker installed, something went wrong with your installation process.

How did you install altair_saver?

ndharari

comment created time in 6 days

issue closedaltair-viz/altair

specifying tooltip causes warning about vegalite type

I have a plot that specifies a list of fields for tooltip (using the mark configuration option). df is a pandas dataframe

        self.artifact = alt.Chart(df).mark_point().encode(
            x=alt.X('right_index:Q', axis=alt.Axis(labels=False, ticks=False)),
            y=alt.Y('left_index:Q', axis=alt.Axis(labels=False, ticks=False)),
            tooltip=['left', 'right', 'probe_id', 'diagram', 'count'],
            color='type:N',
            size=alt.Size('count:Q', scale=alt.Scale(
                type='log',
                base=2,
            )),
        )

When I make this plot, it's all fine, except it throws this warning. If I remove the tooltip, the warning goes away. Is this mean I'm doing something wrong, or should I be using the Tooltip class?

.venv/lib/python3.7/site-packages/altair/utils/core.py:109: UserWarning: I don't know how to infer vegalite type from 'empty'. Defaulting to nominal.

https://github.com/altair-viz/altair/blob/5d27c593e749de4f9bdb3df6c1efb5acf14c8b4c/altair/utils/core.py#L108

closed time in 7 days

odoublewen

issue commentaltair-viz/altair

specifying tooltip causes warning about vegalite type

No problem at all – glad you got it working!

odoublewen

comment created time in 7 days

issue commentaltair-viz/altair

specifying tooltip causes warning about vegalite type

You can specify types for your tooltips as you do for other encodings:

tooltip=['left:N', 'right:N', 'probe_id:N', 'diagram:N', 'count:N']

This will avoid calling the type inference utility for the problematic columns.

odoublewen

comment created time in 7 days

issue commentaltair-viz/altair

Interval Selection Example Bug

This fix has not yet been part of a release. At the next release, the website will be updated.

eitanlees

comment created time in 7 days

issue commentvega/vega-lite

Vega-Lite 4.1.1: some layered specs are invalid

Thanks!

jakevdp

comment created time in 7 days

issue commentaltair-viz/altair

Layered Legends

Legends are only created in Vega-Lite to represent an encoding. If https://github.com/vega/vega-lite/issues/1601 is ever implemented, it will be easier to construct legends for layered values.

But for the time being, I don't think there's any better answer than what you've done above.

eitanlees

comment created time in 7 days

issue commentvega/vega-lite

Vega-Lite 4.1.1: some layered specs are invalid

Just to be clear, will this be rolled back, or should I start adapting Altair with this behavior in mind? Altair is now 2 minor versions behind Vega-Lite because of this bug.

jakevdp

comment created time in 8 days

issue commentaltair-viz/altair

Sort legend by data

Yes, documentation updates are always welcome! The documentation source can be found here: https://github.com/altair-viz/altair/tree/master/doc

Unfortunately we don't currently have any instructions on updating the docs. Let me know if you have questions.

Note that both pages you linked to are automatically generated by sphinx auto-doc, so those aren't the parts of the docs that can be modified. You can more easily modify any of the source files in https://github.com/altair-viz/altair/tree/master/doc/user_guide

Juan-132

comment created time in 8 days

issue commentaltair-viz/altair

Sorting X axis of a layered chart

This is a known issue in Vega-Lite: if you look in the javascript console when rendering the chart, you'll see the following:

[Warning] Dropping sort property {"field":"count","op":"mean"} as unioned domains only support boolean or op "count", "min", and "max".

The workaround is to use one of the supported operations within the sort field; specifically, you can replace alt.SortField(field="count") with alt.EncodingSortField(field="count", op="min") in both places.

Full code:

import pandas as pd
import altair as alt
import numpy as np

# generate random data

col_names = [chr(x) for x in range(ord("a"), ord("z") + 1)]
col_names = np.random.permutation(col_names)

df = pd.concat(
    [
        pd.DataFrame(
            {
                "col": col_names[cnt // 5],
                "cnt_col": str(cnt),
                "count": cnt,
                "value": np.random.randn(cnt) * 1 / cnt * 100,
            }
        )
        for cnt in range(5, 100, 5)
    ]
)

# group and shuffle
grouped_df = (
    (
        df.groupby(["col", "cnt_col", "count"])
        .agg(mean=("value", "mean"), sd=("value", "std"))
        .reset_index()
    )
    .sample(frac=1)
    .reset_index(drop=True)
)

display(grouped_df.head())

base = alt.Chart(grouped_df).transform_calculate(
    ymin="datum.mean-datum.sd", ymax="datum.mean+datum.sd"
)

points = base.mark_point(filled=True, size=20).encode(
    x=alt.X("col:N", sort=alt.EncodingSortField(field="count", op="min")), y="mean"
)

errorbars = points.mark_errorbar().encode(
    y="ymin:Q",
    y2="ymax:Q",
    x=alt.X("col:N", sort=alt.EncodingSortField(field="count", op="min"), axis=None),
)

points + errorbars

visualization (58)

subhashbylaiah

comment created time in 8 days

issue commentaltair-viz/altair

Set color scale for hconcat chart

If you want variables to be represented by color rather than opacity, you should use a color encoding rather than an opacity encoding. Since data is shared across your charts, it also makes sense to remove the independent color scale resolution. It might look something like this:

import altair as alt
import pandas as pd

tmp = pd.read_csv('tmp.csv', sep='\t')

flow = alt.Chart(tmp).mark_line().encode(
    x = alt.X('date:T', axis = alt.Axis(format = '%b')),
    y = 'FLOW:Q',
    color = 'f_l:N')

d = alt.Chart(tmp).mark_line().encode(
    x = alt.X('date:T', axis = alt.Axis(format = '%b')),
    y = alt.Y('swe_depth:Q', axis = alt.Axis(title='SWE Depth (m)')),
    color = 'd_l:N')
cfgi = alt.Chart(tmp).mark_line().encode(
    x = alt.X('date:T', axis = alt.Axis(format = '%b')),
    y = 'CFGI:Q', 
    color = 'c_l:N')

a = alt.layer(flow, cfgi).resolve_scale(y='independent')
b = alt.layer(d,cfgi).resolve_scale(y = 'independent')
c = alt.layer(flow, d).resolve_scale(y = 'independent')

alt.hconcat(a,b,c).resolve_scale(shape='shared').configure(background='white').configure_legend(title=None)

visualization (56)

I don't know what you mean by a "diverging color ramp" in the context of non-quantitative data, but if you want to adjust the default color scheme you can use any of the categorical schemes listed here: https://vega.github.io/vega/docs/schemes/#categorical

danhamill

comment created time in 8 days

issue commentaltair-viz/altair

Set domain for log scale

I don't know of any way to force log domain extents to start and end on values that are not integer powers of the base. You might ask in the Vega-Lite forums to see if anybody knows whether that's possible.

TomBugnon

comment created time in 8 days

push eventaltair-viz/altair

Eitan Lees

commit sha 4626f68fcdaed054b412630ec58511c3ec4bc3e9

DOC: add dual y axis example

view details

Jake Vanderplas

commit sha 5d27c593e749de4f9bdb3df6c1efb5acf14c8b4c

Merge pull request #1962 from eitanlees/second-y-axis DOC: add dual y axis example

view details

push time in 8 days

PR merged altair-viz/altair

DOC: add dual y axis example

visualization (53)

+30 -0

1 comment

1 changed file

eitanlees

pr closed time in 8 days

pull request commentaltair-viz/altair

DOC: add dual y axis example

Looks great - thanks!

Would you also be willing to add a few words (and perhaps similar example or a link to this one) in the docs at https://altair-viz.github.io/user_guide/scale_resolve.html?

eitanlees

comment created time in 8 days

issue commentaltair-viz/altair

Sort legend by data

You can do this with an appropriately constructed EncodingSortField:

import pandas as pd
import altair as alt

df = pd.read_csv("data.txt", parse_dates=['date'])
alt.Chart(df).mark_line().encode(
    x='date',
    y='count',
    color=alt.Color('category',
            sort=alt.EncodingSortField('count', op='mean', order='descending'))
)

visualization (55)

Juan-132

comment created time in 9 days

issue commentaltair-viz/altair

Transform filter appears to incorrectly adhere to specified range

I don't entirely understand why this is breaking, but I found that if you use toNumber() within the expression to force the selection value to be parsed as a number, it works as expected:

.transform_filter(
    '((toNumber({}.time) - 5.0) < datum.time) && (datum.time < toNumber({}.time) + 5.0)'.format(brush.name, brush.name)
)

It may be worth raising this within Vega-Lite itself; I'm not certain what implicit parsing is happening when this is left out.

deflaux

comment created time in 9 days

issue closedaltair-viz/altair

Semantics of concat, layer, etc.

Currently the output of chart1 | chart2 is implemented via alt.concat(chart1, chart2). The semantics are such that chart1 | chart2 | chart3 will yield a single concatenated chart with three subcharts.

In order to obtain this result, concat() is implemented such that

alt.concat(chart1 | chart2, chart3)

will add chart3 to the first entry, which leads to strange results in some cases (e.g. #1953).

I propose to change this such that chart1 | chart2 | chart3 will still yield a single concatenated chart with three entries, while alt.concat(chart1 | chart2, chart3) will yield a nested concat chart with two entries.

For consistency, the same change should be made to alt.concat, alt.layer, alt.hconcat, alt.vconcat, and the associated operators (&, |, +).

closed time in 9 days

jakevdp

issue commentaltair-viz/altair

Semantics of concat, layer, etc.

I looked into this and realized it's already implemented the way I describe in this issue.

jakevdp

comment created time in 9 days

delete branch jakevdp/altair

delete branch : fix-schema-error

delete time in 10 days

push eventaltair-viz/altair

Jake VanderPlas

commit sha c4c32f0da1e924b897341c17dde44e0f64dfbc59

BUG: fix schema validation error in Python 3.8

view details

Jake Vanderplas

commit sha 44dcf81f6780a6ec8b612cdd6091d4c68275bf7e

Merge pull request #1958 from jakevdp/fix-schema-error BUG: fix schema validation error in Python 3.8

view details

push time in 10 days

PR merged altair-viz/altair

BUG: fix schema validation error in Python 3.8

Fixes #1935

+2 -2

0 comment

2 changed files

jakevdp

pr closed time in 10 days

issue closedaltair-viz/altair

Schema validation error fails to print

$ cat test.py
import pandas, altair

d = [{'WijkenEnBuurten': 'Nederland', 'Codering_3': 'NL00', 'Mannen_6': 8475102, 'Vrouwen_7': 8606405, 'SoortRegio_2': 'Land      ', 'GeboorteRelatief_25': 9}, {'WijkenEnBuurten': 'Aa en Hunze', 'Codering_3': 'GM1680', 'Mannen_6': 12603, 'Vrouwen_7': 12683, 'SoortRegio_2': 'Gemeente  ', 'GeboorteRelatief_25': 6}]

df = pandas.DataFrame(d)
a = altair.Data(df)

$ python ./test.py
Traceback (most recent call last):
  File "./t_altair_schema.py", line 5, in <module>
    a = altair.Data(df)
  File "/home/paulm/.local/lib/python3.8/site-packages/altair/vegalite/v3/schema/core.py", line 3741, in __init__
    super(Data, self).__init__(*args, **kwds)
  File "/home/paulm/.local/lib/python3.8/site-packages/altair/utils/schemapi.py", line 154, in __init__
    self.to_dict(validate=True)
  File "/home/paulm/.local/lib/python3.8/site-packages/altair/utils/schemapi.py", line 302, in to_dict
    raise SchemaValidationError(self, err)
altair.utils.schemapi.SchemaValidationError: <exception str() failed>

Somehow the exception can't be turned into a string. I briefly looked at the relevant code in altair.utils.schemapi, but don't immediately see what is going wrong.

This is with Python 3.8.1, altair 3.2.0 on Arch Linux (64-bit)

closed time in 10 days

paulmelis

issue commentaltair-viz/altair

Reformatting ordinal date value

Temporal axis formats do not work with non-temporal values. You are specifying an ordinal encoding with a temporal axis format, which is why it does not work.

What you should do is ensure that your ordinal data is treated as temporal by specifying a time unit with your ordinal encoding. Change your x encoding from

alt.X('month_year:O', title='Month', axis=alt.Axis(format="%b %Y"))

to

alt.X('yearmonth(month_year):O', title='Month')
chankrista

comment created time in 10 days

issue closedaltair-viz/altair

can selection + bind-to-legend have multiple channels?

The interactive legend example indicates a binding to the color channel of the legend. How can we make multiple channels in the legend (color, shape, size, etc.) interactive in the same way (click, shift-click)? e.g.:

import altair as alt
from vega_datasets import data

source = data.iris()

selection = alt.selection_multi(fields=['species', 'petalWidth'], bind='legend')

alt.Chart(source).mark_circle().encode(
    alt.X('sepalLength', scale=alt.Scale(zero=False)),
    alt.Y('sepalWidth', scale=alt.Scale(zero=False, padding=1)),
    color='species',
    size='petalWidth',
    opacity=alt.condition(selection, alt.value(1), alt.value(0.2))
).add_selection(
    selection
)

closed time in 10 days

jowens

issue closedaltair-viz/altair

Question: What kind of Altair user-input should be used to show toggled values / how do we select "all values"?

I'd like to add a user input to a chart (e.g., https://altair-viz.github.io/gallery/multiple_interactions.html). I have data that has an undirected field that is either true or false. I'd like to be able to show three things: true, false, and either true or false. A checkbox thus doesn't seem like the right answer because it has only two states. Doing it in a dropdown seems rather weird. Radio buttons seem right out. could see having two checkboxes, one for undirected and one for directed. First question: From a UI perspective, what is the right way to do this?

Second question: For things with multiple selections, how can we support an all selector? A pulldown makes sense to show multiple selections, but I don't see (by default) how to make it work with "select everything". Pair it with a checkbox that enables the pulldown? (An example of this would be helpful.)

Third question: If I do use a checkbox, how can I make its default checked rather than unchecked?

closed time in 10 days

jowens

issue commentaltair-viz/altair

Title alignment issue in concatenated layered plots

Thinking about this more, I believe this issue warrants a behavior change in Altair. I've opened a new issue to track this: #1959

sterlinm

comment created time in 10 days

issue openedaltair-viz/altair

Semantics of ``concat``, ``layer``, etc.

Currently the output of chart1 | chart2 is implemented via alt.concat(chart1, chart2). The semantics are such that chart1 | chart2 | chart3 will yield a single concatenated chart with three subcharts.

In order to obtain this result, concat() is implemented such that

alt.concat(chart1 | chart2, chart3)

will add chart3 to the first entry, which leads to strange results in some cases (e.g. #1953).

I propose to change this such that chart1 | chart2 | chart3 will still yield a single concatenated chart with three entries, while ``alt.concat(chart1 | chart2, chart3) will yield nested concat charts.

For consistency, the same change should be made to alt.concat, alt.layer, alt.hconcat, alt.vconcat, and the associated operators (&, |, +).

created time in 10 days

PR opened altair-viz/altair

BUG: fix schema validation error in Python 3.8

Fixes #1935

+2 -2

0 comment

2 changed files

pr created time in 10 days

create barnchjakevdp/altair

branch : fix-schema-error

created branch time in 10 days

issue commentaltair-viz/altair

Schema validation error fails to print

Thanks for the report – this only appears to happen with Python 3.8, not with any other supported Py 3.X releases.

paulmelis

comment created time in 10 days

issue closedaltair-viz/altair

Does altair work with Jupyter Notebook ONLY?

Sorry for my naive question.

I just started playing altair.

And, it doesn't show the plot if I ONLY run from the terminal by

python test.py

However, if I convert test.py to test.ipynb, it shows beautifully in Jupyter Notebook.

Does that mean if I still prefer showing the plot from my local computer, I still need to use matplotlib instead ?

Cheers Pei

closed time in 10 days

jiapei100

issue commentvega/vega-lite

Implements `visible` encoding channel

You can make the opacity encoding conditioned on data values using https://vega.github.io/vega-lite/docs/condition.html

christophe-petitjean

comment created time in 11 days

delete branch jakevdp/altair

delete branch : schemagen-cleanup

delete time in 11 days

push eventaltair-viz/altair

Jake VanderPlas

commit sha aa233f5bbb15144ff48b3674420c190a35e1a53c

MAINT: simplify generated schema definitions

view details

Jake Vanderplas

commit sha 52498bfa6552793f0a5212aae5729e18e6809756

Merge pull request #1956 from jakevdp/schemagen-cleanup MAINT: simplify generated schema definitions

view details

push time in 11 days

PR merged altair-viz/altair

MAINT: simplify generated schema definitions

I was looking through the schema generation code and realized that all schema objects share the same root schema, so it's less duplicative to implement it via inheritance.

This should have no user-visible impact.

+18 -759

0 comment

4 changed files

jakevdp

pr closed time in 11 days

issue closedaltair-viz/altair

WSL + jupyterlab - very large options button

This is a slightly odd one, currently if I make an altair plot in jupyterlab using the windows subsystem for linux (WSL) I get a rather large options button:

import numpy as np
import pandas as pd
import altair as alt

df = pd.DataFrame({
    'x': np.random.randn(100),
    'y': np.random.randn(100),
})

alt.Chart(df).encode(x='x', y='y').mark_point()

Capture

Versions:

altair : master or conda OS: Windows 10 + ubuntu WSL jupyterlab: 1.2.6 (perhaps relevant: when I run jupyter labextension install @jupyterlab/vega6-extension I get an error 'ValueError: "@jupyterlab/vega6-extension" is not a valid npm package'` and indeed issue is fixed if I import altair.vegalite.v3 as alt.

closed time in 11 days

jcmgray

issue commentaltair-viz/altair

WSL + jupyterlab - very large options button

This is due to overzealous CSS elsewhere in your JupyterLab window, either in a front end extension or in the output cell of a notebook (not necessarily the current notebook).

Try closing all your notebook tabs in Jupyterlab, then reloading the browser window. If that doesn't work, disable frontend extensions that may be affecting CSS styles and re-launch JupyterLab.

More details: #1845, #1916, #1923

jcmgray

comment created time in 11 days

push eventaltair-viz/altair

Eitan Lees

commit sha 5fe32498df5271f755d9f998a222bd82416b7474

DOC: add scatter with loess example

view details

Eitan Lees

commit sha 6e23a87ddc2529dd65dbf63a223bdf83dfb2408c

DOC: use fold transform on loess example

view details

Eitan Lees

commit sha 7e96107f608686fb63240909537952fdedef2607

DOC: reformat loess example data

view details

Jake Vanderplas

commit sha 7549c18e8848d02bc20f81076161184e875a3884

Merge pull request #1955 from eitanlees/scatter-loess DOC: add scatter with loess example

view details

push time in 11 days

PR merged altair-viz/altair

DOC: add scatter with loess example

visualization (50)

I thought an example of adding multiple grouped LOESS lines to a scatter plot could be a useful addition to the docs.

+31 -0

8 comments

1 changed file

eitanlees

pr closed time in 11 days

pull request commentaltair-viz/altair

DOC: add scatter with loess example

Thanks!

eitanlees

comment created time in 11 days

PR opened altair-viz/altair

MAINT: simplify generated schema definitions

I was looking through the schema generation code and realized that all schema objects share the same root schema, so it's less duplicative to implement it via inheritance.

This should have no user-visible impact.

+18 -759

0 comment

4 changed files

pr created time in 12 days

create barnchjakevdp/altair

branch : schemagen-cleanup

created branch time in 12 days

pull request commentaltair-viz/altair

DOC: add scatter with loess example

Yeah, that looks great: everything is very explicit and understandable, even to a reader who's not very familiar with pandas.

Would you be willing to update this PR with that style?

eitanlees

comment created time in 12 days

pull request commentaltair-viz/altair

DOC: add scatter with loess example

In general do we want to use built in transforms?

Good question... thinking about it, I'd say we should use built-in transforms whenever they make the examples clearer. I think the fold transform here is a bit clearer than pd.melt; I also think that reset_index() here is probably clearer than using transform_window(x='count()').

eitanlees

comment created time in 12 days

pull request commentaltair-viz/altair

DOC: add scatter with loess example

Nice example! What would you think about replacing the melt() operation with a fold transform?

eitanlees

comment created time in 12 days

issue closedaltair-viz/altair

Specifying Images as labels along Y-axis

Hi, Is there a way to specify images as labels along Y-axis in Altair as shown in the image? (Image Source: https://in.pcmag.com/news/132040/countries-that-spend-the-most-time-on-social-media-face-the-most-consequences)

Countries

closed time in 12 days

gowrishankarnath

issue commentaltair-viz/altair

save as svg changes fonts and margins

Thanks for the report – this looks like a bug on the vega side.

deisi

comment created time in 12 days

issue commentaltair-viz/altair

Title alignment issue in concatenated layered plots

Syntactically, A | B | C means "create a single concat chart containing A, B, and C". So when you do (A | B) | (C | D), it means "create a single concat chart containing A, B, and (C | D)".

This is almost always the right thing to do, but in your case you've hit a corner where it does not make as much sense.

To specify the concat structure you want, you can replace left | right with

alt.ConcatChart(concat=[left, right])
sterlinm

comment created time in 13 days

issue commentaltair-viz/altair

Does altair work with Jupyter Notebook ONLY?

No, see https://altair-viz.github.io/user_guide/faq.html#does-altair-work-with-ipython-terminal-pycharm-spyder-my-favorite-ide

jiapei100

comment created time in 13 days

issue closedvega/ipyvega

is ipyvega included in jupyter notebook by default?

➜  vega git:(master) jupyter notebook --version
6.0.3

jupyter nbextension install --sys-prefix --py vega # not needed in notebook >= 5.3

closed time in 13 days

jiapei100

issue commentvega/ipyvega

is ipyvega included in jupyter notebook by default?

No, it must be installed from pip. In notebook version 5.3 or newer, pip installing the package is sufficient to install the nbextension. Previous to that, the nbextension had to be installed manually.

jiapei100

comment created time in 13 days

issue commentaltair-viz/altair

Reformatting ordinal date value

If you use a timeUnit with an ordinal type as I suggested in https://github.com/altair-viz/altair/issues/1951#issuecomment-583104870, it should give you an ordinal axis with proper time formatting.

chankrista

comment created time in 13 days

issue commentaltair-viz/altair

Reformatting ordinal date value

Try using a time unit instead of an axis format string; e.g.

alt.X('yearmonth(month_year):O', title='Month')

I think the reason the format string didn't work is because you're specifying that your data is of ordinal type, not temporal type.

chankrista

comment created time in 13 days

issue commentaltair-viz/altair

Specifying Images as labels along Y-axis

There are two ways to do something like this. Images can be included in the labels if the images can be expressed as unicode emojis; here is an example:

import altair as alt
import pandas as pd

df = pd.DataFrame({
    "country": ["Philippines 🇵🇭", "Nigeria 🇳🇬", "Mexico 🇲🇽"],
    "value": [100, 96, 94]
})

alt.Chart(df).mark_bar().encode(
    y='country:N',
    x='value:Q'
)

visualization - 2020-02-06T055441 783

If the images you want to use are available by URL, you can use chart concatenation to achieve roughly the same effect:

df['flag_image'] = [
    f"https://www.countries-ofthe-world.com/flags-normal/flag-of-{country}.png"
    for country in df['country']
]

flags = alt.Chart(df).mark_image().encode(
    y=alt.Y('country', axis=alt.Axis(domainOpacity=0, ticks=False)),
    url="flag_image"
)

chart = alt.Chart(df).mark_bar().encode(
    y=alt.Y('country', axis=None),
    x='value'
)

alt.concat(
    flags, chart
).configure_concat(
    spacing=0
).configure_view(
    strokeOpacity=0
)

Screen Shot 2020-02-06 at 6 03 48 AM

gowrishankarnath

comment created time in 13 days

push eventaltair-viz/altair

Jake Vanderplas

commit sha 61d72d5c620ef6f88330ab94c302e004b61b6814

Add vega-lite citation to README

view details

push time in 13 days

issue commentaltair-viz/altair

Scientific citation

You might also cite https://dl.acm.org/doi/10.1109/TVCG.2016.2599030, which Altair is based on.

deisi

comment created time in 13 days

issue commentaltair-viz/altair

Scientific citation

Sure, see https://github.com/altair-viz/altair#citing-altair

deisi

comment created time in 13 days

issue commentaltair-viz/altair

Error bars on binned scatter plot

Here's an example of the workaround:

import pandas as pd
import altair as alt

out = pd.read_csv('data.tsv', delim_whitespace=True)

base = alt.Chart(out).transform_bin(
    'binned_temp', field='temp', bin=alt.Bin(step=0.5)
).encode(
    x = alt.X('binned_temp:O', sort='descending', axis=alt.Axis(title='Soil Temperature (°C)')),
)

chart1 = base.mark_circle(color='red').encode(
    y = alt.Y('mean(CFGI)', axis = alt.Axis(title='CFGI'))
)

error = base.mark_errorbar().encode(
    y = alt.Y('CFGI', scale=alt.Scale(zero = False))
)

alt.layer(error, chart1).facet('station').configure_header(title=None).configure(background = 'white')

visualization (52)

danhamill

comment created time in 14 days

issue commentaltair-viz/altair

Error bars on binned scatter plot

This looks like a Vega-Lite issue; I've reported it upstream: https://github.com/vega/vega-lite/issues/5863

A workaround would be to use transform_bin() directly, rather than specifying the bin within the encoding.

danhamill

comment created time in 14 days

issue openedvega/vega-lite

Errorbar: discrepancy between bin transform and binned encoding

Drawing an errorbar within bin-transformed data works as expected (vega editor):

{
  "data": {"url": "data/cars.json"},
  "transform": [{"bin": true, "field": "Horsepower", "as": "xbin"}],
  "mark": "errorbar",
  "encoding": {
    "x": {"type": "ordinal", "field": "xbin"},
    "y": {
      "type": "quantitative",
      "aggregate": "mean",
      "field": "Miles_per_Gallon"
    }
  }
}

visualization (50)

When the bin argument is moved into the encoding, however, things look strange (vega editor):

{
  "data": {"url": "data/cars.json"},
  "mark": "errorbar",
  "encoding": {
    "x": {"type": "nominal", "bin": true, "field": "Horsepower"},
    "y": {
      "type": "quantitative",
      "aggregate": "mean",
      "field": "Miles_per_Gallon"
    }
  }
}

visualization (51)

I suspect this is due to the x and x2 encodings implied by the inline bin transform, but it would be nice to be able to use the encoding bin for a case like this.

First reported in https://github.com/altair-viz/altair/issues/1948

created time in 14 days

issue commentaltair-viz/altair

Grouped Horizontal bar plot with reduced row spacing

When you run conda list, you are using a shell in one environment. When you run import altair, you are using Python in another environment. The two environments are not necessarily the same, even if you run jupyter notebook from the same shell where you run conda list.. The stackoverflow answer has details that might help.

danhamill

comment created time in 14 days

issue commentaltair-viz/altair

Grouped Horizontal bar plot with reduced row spacing

All of the discrepancies you're seeing are likely due to your Jupyter notebook connecting to a different kernel than you expect it to be connected to.

danhamill

comment created time in 14 days

issue commentaltair-viz/altair

Grouped Horizontal bar plot with reduced row spacing

This generally means that your Jupyter notebook kernel is pointing to a different Python installation than your shell where you run conda. See https://stackoverflow.com/questions/39007571/running-jupyter-with-multiple-python-and-ipython-paths/39022003#39022003 for more information

If you just want to install Altair in the current kernel, you can use Jupyter's %pip install or %conda install magic command and it will install the package in the right place.

danhamill

comment created time in 14 days

issue commentaltair-viz/altair

Grouped Horizontal bar plot with reduced row spacing

The spacing argument was added in Altair version 4.0. Update your Altair package, and you should be able to use it.

danhamill

comment created time in 15 days

issue commentvega/vega-lite

Vega-Lite 4.1.1: some layered specs are invalid

Were there any other changes to allowed entries in unit specs?

jakevdp

comment created time in 15 days

more