Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/bug-report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ body:
label: What happened?
description: |
Describe what happened and how to reproduce the bug.
Include the full code and data to reproduce it. Use a simple toy data set, e.g. from `vega_datasets`.
Include the full code and data to reproduce it. Use a simple toy data set, e.g. from `altair.datasets`.
validations:
required: true
- type: textarea
Expand Down
11 changes: 4 additions & 7 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ Every example should:
- not make any external calls to download data within the script (i.e. don't
use urllib). You can define your data directly within the example file,
generate your data using pandas and numpy, or you can use data
available in the `vega_datasets` package.
available in the `altair.datasets` module.

The easiest way to get started would be to adapt examples from the [Vega-Lite
example gallery](https://vega.github.io/vega-lite/examples/) which are missing
Expand All @@ -225,12 +225,9 @@ Some additional notes:
If the example requires multiple dataframes then this does not apply. See
other examples for guidance.
- Example code should not require downloading external datasets. We suggest
using the `vega_datasets` package if possible.
If you are using the `vega_datasets` package there are multiple ways to refer
to a data source. If the dataset you would like to use is included in local
installation (`vega_datasets.local_data.list_datasets()`) then the data can
be referenced directly, such as `source = data.iris()`. If the data is not
included then it should be referenced by URL, such as `source =
using the `altair.datasets` module if possible.
If you are using the `altair.datasets` module there are multiple ways to refer
to a data source. The data can be referenced directly, such as `source = data.penguins()`, or it can be referenced by URL, such as `source =
data.movies.url`. This is to ensure that Altair's automated test suite does
not depend on availability of external HTTP resources.
- If VlConvert does not support PNG export of the chart (e.g. in the case of emoji),
Expand Down
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ Here is an example using Vega-Altair to quickly visualize and display a dataset
import altair as alt

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

alt.Chart(cars).mark_point().encode(
Expand All @@ -48,7 +48,7 @@ With a few modifications to the example above we can create a linked histogram t

```python
import altair as alt
from vega_datasets import data
from altair.datasets import data

source = data.cars()

Expand Down
2 changes: 1 addition & 1 deletion altair/theme.py
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,7 @@ def custom_theme() -> theme.ThemeConfig:

Until another theme has been enabled, all charts will use defaults set in ``custom_theme()``::

from vega_datasets import data
from altair.datasets import data

source = data.stocks()
lines = (
Expand Down
28 changes: 16 additions & 12 deletions altair/vegalite/v6/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -996,14 +996,16 @@ def then(self, statement: _StatementType, /, **kwds: Any) -> Then[Any]:
Simple conditions may be expressed without defining a default::

import altair as alt
from vega_datasets import data
from altair.datasets import data

source = data.movies()
predicate = (alt.datum.IMDB_Rating == None) | (alt.datum.Rotten_Tomatoes_Rating == None)
predicate = (alt.datum["IMDB Rating"] == None) | (
alt.datum["Rotten Tomatoes Rating"] == None
)

alt.Chart(source).mark_point(invalid=None).encode(
x="IMDB_Rating:Q",
y="Rotten_Tomatoes_Rating:Q",
x="IMDB Rating:Q",
y="Rotten Tomatoes Rating:Q",
color=alt.when(predicate).then(alt.value("grey")),
)
"""
Expand Down Expand Up @@ -1072,7 +1074,7 @@ def otherwise(
Points outside of ``brush`` will not appear highlighted::

import altair as alt
from vega_datasets import data
from altair.datasets import data

source = data.cars()
brush = alt.selection_interval()
Expand Down Expand Up @@ -1159,7 +1161,7 @@ def when(
Chain calls to express precise queries::

import altair as alt
from vega_datasets import data
from altair.datasets import data

source = data.cars()
color = (
Expand Down Expand Up @@ -1264,19 +1266,21 @@ def then(self, statement: _StatementType, /, **kwds: Any) -> Then[_Conditions]:
Multiple conditions with an implicit default::

import altair as alt
from vega_datasets import data
from altair.datasets import data

source = data.movies()
predicate = (alt.datum.IMDB_Rating == None) | (alt.datum.Rotten_Tomatoes_Rating == None)
predicate = (alt.datum["IMDB Rating"] == None) | (
alt.datum["Rotten Tomatoes Rating"] == None
)
color = (
alt.when(predicate)
.then(alt.value("grey"))
.when(alt.datum.IMDB_Votes < 5000)
.when(alt.datum["IMDB Votes"] < 5000)
.then(alt.value("lightblue"))
)

alt.Chart(source).mark_point(invalid=None).encode(
x="IMDB_Rating:Q", y="Rotten_Tomatoes_Rating:Q", color=color
x="IMDB Rating:Q", y="Rotten Tomatoes Rating:Q", color=color
)
"""
condition = self._when_then(statement, kwds)
Expand Down Expand Up @@ -1344,7 +1348,7 @@ def when(
Setting up a common chart::

import altair as alt
from vega_datasets import data
from altair.datasets import data

source = data.cars()
brush = alt.selection_interval()
Expand Down Expand Up @@ -3166,7 +3170,7 @@ def transform_filter(

import altair as alt
from altair import datum
from vega_datasets import data
from altair.datasets import data

source = data.population.url
chart = (
Expand Down
2 changes: 1 addition & 1 deletion doc/case_studies/exploring-weather.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ dataframes, and contains a loader for this and other built-in datasets:
.. altair-plot::
:output: repr

from vega_datasets import data
from altair.datasets import data

df = data.seattle_weather()
df.head()
Expand Down
1 change: 0 additions & 1 deletion doc/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,6 @@
},
],
"header_links_before_dropdown": 4,
"announcement": """This website is for version 5. You can find the documentation for version 4 <a href='https://altair-viz.github.io/altair-viz-v4/'>here</a>.""",
"analytics": {
"plausible_analytics_domain": "altair-viz.github.io",
"plausible_analytics_url": ("https://views.scientific-python.org/js/script.js"),
Expand Down
1 change: 0 additions & 1 deletion doc/getting_started/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,5 @@ for details on how to contribute to the Altair project.

.. _conda: https://docs.conda.io/
.. _Vega-Lite: http://vega.github.io/vega-lite
.. _vega_datasets: https://github.com/altair-viz/vega_datasets
.. _JupyterLab: http://jupyterlab.readthedocs.io/
.. _Jupyter Notebook: https://jupyter-notebook.readthedocs.io/
2 changes: 1 addition & 1 deletion doc/getting_started/overview.rst
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ an interactive scatter plot:
import altair as alt

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

# make the chart
Expand Down
8 changes: 0 additions & 8 deletions doc/getting_started/resources.rst
Original file line number Diff line number Diff line change
Expand Up @@ -104,14 +104,6 @@ Altair backend for the pandas plotting API.
.. List of links.
.. _altair_pandas: https://github.com/altair-viz/altair_pandas

vega_datasets_
~~~~~~~~~~~~~~

Offline access to the Vega datasets used in the Altair documentation.

.. List of links.
.. _vega_datasets: https://github.com/altair-viz/vega_datasets

altair_recipes_
~~~~~~~~~~~~~~~

Expand Down
28 changes: 14 additions & 14 deletions doc/user_guide/compound_charts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ same data; for example:
.. altair-plot::

import altair as alt
from vega_datasets import data
from altair.datasets import data

stocks = data.stocks.url

Expand Down Expand Up @@ -76,22 +76,22 @@ heat-map:
.. altair-plot::

import altair as alt
from vega_datasets import data
from altair.datasets import data

source = data.movies.url

heatmap = alt.Chart(source).mark_rect().encode(
alt.X('IMDB_Rating:Q').bin(),
alt.Y('Rotten_Tomatoes_Rating:Q').bin(),
alt.X('IMDB Rating:Q').bin(),
alt.Y('Rotten Tomatoes Rating:Q').bin(),
alt.Color('count()').scale(scheme='greenblue')
)

points = alt.Chart(source).mark_circle(
color='black',
size=5,
).encode(
x='IMDB_Rating:Q',
y='Rotten_Tomatoes_Rating:Q',
x='IMDB Rating:Q',
y='Rotten Tomatoes Rating:Q',
)

heatmap + points
Expand Down Expand Up @@ -121,7 +121,7 @@ distribution of its points:
.. altair-plot::

import altair as alt
from vega_datasets import data
from altair.datasets import data

penguins = data.penguins.url

Expand Down Expand Up @@ -174,7 +174,7 @@ with a ``brush`` selection to add interaction:
.. altair-plot::

import altair as alt
from vega_datasets import data
from altair.datasets import data

source = data.sp500.url

Expand Down Expand Up @@ -219,7 +219,7 @@ showing how ``repeat`` can be used to build the chart more efficiently:
.. altair-plot::

import altair as alt
from vega_datasets import data
from altair.datasets import data

penguins = data.penguins.url

Expand Down Expand Up @@ -251,7 +251,7 @@ method, makes this type of chart a bit easier to produce:
.. altair-plot::

import altair as alt
from vega_datasets import data
from altair.datasets import data
penguins = data.penguins.url

alt.Chart(penguins).mark_point().encode(
Expand All @@ -271,21 +271,21 @@ encodings for the row and/or column which can be referred to in the chart's
encoding specification using ``alt.repeat('row')`` or ``alt.repeat('column')``.

Another option to use the ``repeat`` method is for layering. Here below the
columns ``US_Gross`` and ``Worldwide_Gross`` are layered on the ``y``-axis
columns ``US Gross`` and ``Worldwide Gross`` are layered on the ``y``-axis
using ``alt.repeat('layer')``:

.. altair-plot::

import altair as alt
from vega_datasets import data
from altair.datasets import data

source = data.movies()

alt.Chart(source).mark_line().encode(
x=alt.X("IMDB_Rating").bin(),
x=alt.X("IMDB Rating").bin(),
y=alt.Y(alt.repeat('layer')).aggregate('mean').title("Mean of US and Worldwide Gross"),
color=alt.ColorDatum(alt.repeat('layer'))
).repeat(layer=["US_Gross", "Worldwide_Gross"])
).repeat(layer=["US Gross", "Worldwide Gross"])

Currently ``repeat`` can only be encodings (not, e.g., data transforms)
but there is discussion within the Vega-Lite community about making this pattern
Expand Down
8 changes: 4 additions & 4 deletions doc/user_guide/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ the :meth:`Chart.configure_header` method. Here is an example:
.. altair-plot::

import altair as alt
from vega_datasets import data
from altair.datasets import data

source = data.cars.url

Expand Down Expand Up @@ -142,7 +142,7 @@ Here is an example:
.. altair-plot::

import altair as alt
from vega_datasets import data
from altair.datasets import data

source = data.cars.url

Expand Down Expand Up @@ -270,7 +270,7 @@ Here is an example:
.. altair-plot::

import altair as alt
from vega_datasets import data
from altair.datasets import data

source = data.cars.url

Expand Down Expand Up @@ -305,7 +305,7 @@ be controlled:
.. altair-plot::

import altair as alt
from vega_datasets import data
from altair.datasets import data

source = data.cars.url

Expand Down
Loading