vgplot
A Python API for authoring Mosaic visualizations. Build declarative, interactive plots backed by DuckDB — in notebooks, as JSON specs, or as part of a data pipeline.
vgplot produces Mosaic View objects that can be rendered with mosaic-widget or exported to JSON for use in a browser. Data sources and parameters defined as local variables are automatically discovered at render time.
Installation
pip install vgplot
To render visualizations in the widget, install the widget:
pip install mosaic-widget
Usage
File-based data
Load data from a file using vg.parquet(), vg.csv(), or vg.table(), pass it directly to a mark, then call view.show() or view:
import vgplot as vg
athletes = vg.parquet("data/athletes.parquet")
view = vg.plot(
vg.dot(athletes, x="weight", y="height", fill="sex", opacity=0.5),
vg.width(600),
vg.height(400),
)
view
Interactive selections
Params and selections are first-class objects. Declare them before the view so they can be referenced by multiple marks or interactors:
import vgplot as vg
flights = vg.parquet("data/flights-200k.parquet")
brush = vg.selection.crossfilter()
view = vg.vconcat(
vg.plot(
vg.rect_y(
flights,
x=vg.bin("delay"),
y=vg.count(),
filter_by=brush,
fill="steelblue",
inset_left=0.5,
inset_right=0.5,
),
vg.interval_x(bind=brush),
vg.x_domain("Fixed"),
vg.x_label("Arrival Delay (min)"),
vg.height(200),
),
vg.plot(
vg.rect_y(
flights,
x=vg.bin("time"),
y=vg.count(),
filter_by=brush,
fill="steelblue",
inset_left=0.5,
inset_right=0.5,
),
vg.interval_x(bind=brush),
vg.x_domain("Fixed"),
vg.x_label("Departure Time (hour)"),
vg.height(200),
),
)
view
Scalar params and input widgets
Use vg.param() for scalar parameters bound to input controls:
import vgplot as vg
walk = vg.parquet("data/random-walk.parquet")
bias = vg.param(0)
view = vg.vconcat(
vg.slider(label="Bias", bind=bias, min=0, max=1000, step=1),
vg.plot(
vg.area_y(walk, x="t", y=vg.sql("v + $bias")), vg.width(680), vg.height(200)
),
)
view
Key concepts
| Concept | Python API |
|---|---|
| File-based data | vg.parquet(path), vg.csv(path), vg.spatial(path), vg.table(query) |
| Mark | vg.dot(...), vg.bar_y(...), vg.area_y(...), vg.line_y(...), … |
| Aggregation / transform | vg.count(), vg.bin("col"), vg.avg("col"), vg.sum("col"), … |
| SQL expression | vg.sql("expr") — use $param to interpolate a param, e.g. vg.sql("v + $bias") |
| Plot attributes | vg.width(n), vg.height(n), vg.x_label("…"), vg.color_scheme("…"), … |
| Interactor | vg.interval_x(...), vg.interval_xy(...), vg.region(...), vg.highlight(...), … |
| Layout | vg.vconcat(...), vg.hconcat(...), vg.vspace(n), vg.hspace(n) |
| Crossfilter selection | vg.selection.crossfilter() |
| Intersect / union selection | vg.selection.intersect(), vg.selection.union() |
| Scalar param | vg.param(value) |
| Input widgets | vg.slider(...), vg.menu(...), vg.select(...), vg.checkbox(...) |
| Named data reference | vg.source("table_name") |
| Render | view.show() or view as last cell expression in notebooks |
Option names match the vgplot API reference, but in snake_case. For example, xDomain → x_domain, colorScheme → color_scheme, filterBy → filter_by.
Any mark or directive not listed above is also accessible by its snake_case name — vg.regression_y(...) and vg.x_tick_rotate(45) work without explicit exports.
Exporting specs
view.to_dict() returns a plain Python dictionary. view.to_json() returns a JSON string:
from pprint import pprint
pprint(view.to_dict())
print(view.to_json(indent=2))
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file vgplot-0.30.0.tar.gz.
File metadata
- Download URL: vgplot-0.30.0.tar.gz
- Upload date:
- Size: 26.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
04097eb1f8c104d01c92400614d9dcd9f32cad3e67c536a2fa29d66b4faf34ae
|
|
| MD5 |
b7440a5187af2c86604134e12f7fadaa
|
|
| BLAKE2b-256 |
c03bdb223ee3397d4e0da28895ec7d3667a10b012c3e6aa0cc20b271517d89c9
|
Provenance
The following attestation bundles were made for vgplot-0.30.0.tar.gz:
Publisher:
release.yml on uwdata/mosaic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vgplot-0.30.0.tar.gz -
Subject digest:
04097eb1f8c104d01c92400614d9dcd9f32cad3e67c536a2fa29d66b4faf34ae - Sigstore transparency entry: 2400026675
- Sigstore integration time:
-
Permalink:
uwdata/mosaic@73a7c742e48f38b48ba2b8a379f902c7be49c293 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/uwdata
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@73a7c742e48f38b48ba2b8a379f902c7be49c293 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file vgplot-0.30.0-py3-none-any.whl.
File metadata
- Download URL: vgplot-0.30.0-py3-none-any.whl
- Upload date:
- Size: 25.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
839c922eaed1217d0b9ff4c6a2562d90bd0a0860ecd12cdd4e6c94014e5a1847
|
|
| MD5 |
3eb21c6e3099760b863c08f81375dd7e
|
|
| BLAKE2b-256 |
f8eee0b2e980cc7f99591fe62b5fe320a140c37ad5b93dd5ee0988c47408c986
|
Provenance
The following attestation bundles were made for vgplot-0.30.0-py3-none-any.whl:
Publisher:
release.yml on uwdata/mosaic
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
vgplot-0.30.0-py3-none-any.whl -
Subject digest:
839c922eaed1217d0b9ff4c6a2562d90bd0a0860ecd12cdd4e6c94014e5a1847 - Sigstore transparency entry: 2400026720
- Sigstore integration time:
-
Permalink:
uwdata/mosaic@73a7c742e48f38b48ba2b8a379f902c7be49c293 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/uwdata
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@73a7c742e48f38b48ba2b8a379f902c7be49c293 -
Trigger Event:
workflow_dispatch
-
Statement type: