跳转到主要内容

Vega-Altair:Python的声明性统计可视化库。

项目描述

Vega-Altair

github actions typedlib_mypy JOSS Paper PyPI - Downloads

Vega-Altair 是一个用于 Python 的声明式统计可视化库。使用 Vega-Altair,您可以花费更多时间理解数据和其含义。Vega-Altair 的 API 简单、友好且一致,建立在强大的 Vega-Lite JSON 规范之上。这种优雅的简单性用最少的代码产生美丽而有效的可视化。

Vega-Altair 由 Jake VanderplasBrian Granger 开发,并与 UW Interactive Data Lab 亲密合作。 VEGA-Altair 开源项目与 Altair Engineering, Inc. 无关。

文档

请参阅 Vega-Altair 的文档网站 以及 教程笔记本。您可以通过点击以下徽章之一在浏览器中直接运行笔记本:

Binder Colab

示例

以下是一个示例,使用 Vega-Altair 在 JupyterLab 中快速可视化和显示数据集,使用原生的 Vega-Lite 渲染器。

import altair as alt

# load a simple dataset as a pandas DataFrame
from vega_datasets import data
cars = data.cars()

alt.Chart(cars).mark_point().encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color='Origin',
)

Vega-Altair Visualization

Vega-Altair 的一个独特功能,继承自 Vega-Lite,是除了可视化之外,还有 交互 的声明式语法。通过对上面的示例进行一些修改,我们可以创建一个基于散点图选择的筛选直方图的链接直方图。

import altair as alt
from vega_datasets import data

source = data.cars()

brush = alt.selection_interval()

points = alt.Chart(source).mark_point().encode(
    x='Horsepower',
    y='Miles_per_Gallon',
    color=alt.condition(brush, 'Origin', alt.value('lightgray'))
).add_params(
    brush
)

bars = alt.Chart(source).mark_bar().encode(
    y='Origin',
    color='Origin',
    x='count(Origin)'
).transform_filter(
    brush
)

points & bars

Vega-Altair Visualization Gif

功能

  • 精心设计的声明式 Python API。
  • 自动生成的内部 Python API 确保可视化经过类型检查,并与 Vega-Lite 规范完全一致。
  • 在 JupyterLab、Jupyter Notebook、Visual Studio Code、GitHub 和 nbviewer 以及许多其他地方显示可视化。
  • 将可视化导出为各种格式,如 PNG/SVG 图像、独立的 HTML 页面和 在线 Vega-Lite 编辑器
  • 将可视化序列化为 JSON 文件。

安装

Vega-Altair 可以通过以下方式安装:

pip install altair

如果您使用 conda 包管理器,则等效命令是:

conda install altair -c conda-forge

有关完整的安装说明,请参阅 文档

获取帮助

如果您在文档中找不到答案的问题,您可以在 StackOverflow 上使用 altair 标签发布。对于错误和功能请求,请打开 Github Issue

开发

Hatch project Ruff pytest

有关如何安装开发包的说明,请参阅 文档

要运行测试和代码检查器,使用:

hatch test

有关如何将您的开发贡献回 Vega-Altair 存储库的信息,请参阅 CONTRIBUTING.md

引用 Vega-Altair

JOSS Paper

如果您在学术工作中使用 Vega-Altair,请考虑引用以下链接:https://joss.theoj.org/papers/10.21105/joss.01057

@article{VanderPlas2018,
    doi = {10.21105/joss.01057},
    url = {https://doi.org/10.21105/joss.01057},
    year = {2018},
    publisher = {The Open Journal},
    volume = {3},
    number = {32},
    pages = {1057},
    author = {Jacob VanderPlas and Brian Granger and Jeffrey Heer and Dominik Moritz and Kanit Wongsuphasawat and Arvind Satyanarayan and Eitan Lees and Ilia Timofeev and Ben Welsh and Scott Sievert},
    title = {Altair: Interactive Statistical Visualizations for Python},
    journal = {Journal of Open Source Software}
}

此外,请考虑引用基于 Vega-Altair 的 Vega-Lite 项目:Vega-Lite,相关文献请参考:https://dl.acm.org/doi/10.1109/TVCG.2016.2599030

@article{Satyanarayan2017,
    author={Satyanarayan, Arvind and Moritz, Dominik and Wongsuphasawat, Kanit and Heer, Jeffrey},
    title={Vega-Lite: A Grammar of Interactive Graphics},
    journal={IEEE transactions on visualization and computer graphics},
    year={2017},
    volume={23},
    number={1},
    pages={341-350},
    publisher={IEEE}
} 

项目详情


下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。

源代码分布

altair-5.4.1.tar.gz (636.5 kB 查看散列值)

上传时间 源代码

构建分布

altair-5.4.1-py3-none-any.whl (658.1 kB 查看散列值)

上传时间 Python 3

支持者

AWS AWS 云计算和安全赞助商 Datadog Datadog 监控 Fastly Fastly CDN Google Google 下载分析 Microsoft Microsoft PSF 赞助商 Pingdom Pingdom 监控 Sentry Sentry 错误日志 StatusPage StatusPage 状态页面