Skip to main content

A python engine for evaluating Altair transforms.

Project description

altair-transform

Python evaluation of Altair/Vega-Lite transforms.

build status

Example

The Vega-Lite specification includes the ability to apply a wide range of transformations to input data within the chart specification. As an example, here is a sliding window average of a Gaussian random walk, implemented in Altair:

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

rand = np.random.RandomState(12345)

df = pd.DataFrame({
    'x': np.arange(200),
    'y': rand.randn(200).cumsum()
})

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

line = alt.Chart(df).transform_window(
    ymean='mean(y)',
    sort=[alt.SortField('x')],
    frame=[5, 5]
).mark_line(color='red').encode(
    x='x:Q',
    y='ymean:Q'
)

points + line

Altair Visualization

Because the transform is encoded within the renderer, however, it is not easy from Altair to access the computed values.

This is where altair_transform comes in. It includes a (nearly) complete Python implementation of Vega-Lite's transform layer, so that you can easily extract a pandas dataframe with the computed values shown in the chart:

from altair_transform import extract_data
data = extract_data(line)
data.head()
x y ymean
0 0 -0.204708 0.457749
1 1 0.274236 0.771093
2 2 -0.245203 1.041320
3 3 -0.800933 1.336943
4 4 1.164847 1.698085

From here, you can work with the transformed data directly in Python.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

altair_transform-0.1.0.tar.gz (27.6 kB view details)

Uploaded Source

Built Distribution

altair_transform-0.1.0-py2.py3-none-any.whl (34.4 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file altair_transform-0.1.0.tar.gz.

File metadata

  • Download URL: altair_transform-0.1.0.tar.gz
  • Upload date:
  • Size: 27.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2

File hashes

Hashes for altair_transform-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6d910832091aee289e8582c168e37794f62076bcea6d9333aa4a919cad0c8c37
MD5 f263ae04969647ef4937f80cab10dd33
BLAKE2b-256 1537d8135fc0600c3c7e9768d22eda145ced7f9fbea8f34fb157f9a0555e4f5f

See more details on using hashes here.

File details

Details for the file altair_transform-0.1.0-py2.py3-none-any.whl.

File metadata

  • Download URL: altair_transform-0.1.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 34.4 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/40.8.0 requests-toolbelt/0.9.1 tqdm/4.32.2 CPython/3.7.2

File hashes

Hashes for altair_transform-0.1.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0f861a864aceaf8347e197bddedb7343e5300064305e28ed8f5cc4ef57755a51
MD5 b90571579f10d6dc8a153c9ff83d3cb9
BLAKE2b-256 d576d45712f332c0cc0a1853195972fd92a82d37369986bdda9992b0a0e9c5a8

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page