Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

documentation on spatial data #2750

Merged
merged 10 commits into from
Dec 24, 2022
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
1 change: 1 addition & 0 deletions doc/user_guide/data.rst
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ data before usage in Altair using GeoPandas for example as such:
:hidden:

self
data/index
encodings/index
marks/index
transform/index
Expand Down
8 changes: 8 additions & 0 deletions doc/user_guide/data/dataframe.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. currentmodule:: altair

.. _user-guide-dataframe-data:

DataFrame
~~~~~~~~~

Describe
8 changes: 8 additions & 0 deletions doc/user_guide/data/dict.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. currentmodule:: altair

.. _user-guide-dict-data:

Dictionary
~~~~~~~~~~

Describe
8 changes: 8 additions & 0 deletions doc/user_guide/data/generator.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.. currentmodule:: altair

.. _user-guide-generator-data:

Generated data
~~~~~~~~~~~~~~

Describe
58 changes: 58 additions & 0 deletions doc/user_guide/data/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
.. currentmodule:: altair

.. _user-guide-data:

Data
~~~~

The basic data model used by Altair is tabular data,
similar to a spreadsheet or database table.
Individual datasets are assumed to contain a collection of records (rows),
which may contain any number of named data fields (columns).
Each top-level chart object (i.e. :class:`Chart`, :class:`LayerChart`,
:class:`VConcatChart`, :class:`HConcatChart`, :class:`RepeatChart`,
and :class:`FacetChart`) accepts a dataset as its first argument.

While the most common way to provide Altair with a dataset is via a pandas DataFrame,
there are many different ways of specifying a dataset:

========================================= ================================================================================
Data Description
========================================= ================================================================================
:ref:`user-guide-dataframe-data` A `pandas DataFrame <http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html>`_.
:ref:`user-guide-dict-data` A :class:`Data` or related object (i.e. :class:`UrlData`, :class:`InlineData`, :class:`NamedData`).
:ref:`user-guide-url-data` A url string pointing to a ``json`` or ``csv`` formatted text file.
:ref:`user-guide-spatial-data` A `geopandas GeoDataFrame <http://geopandas.org/data_structures.html#geodataframe>`_, `Shapely Geometries <https://shapely.readthedocs.io/en/latest/manual.html#geometric-objects>`_, `GeoJSON Objects <https://github.com/jazzband/geojson#geojson-objects>`_ or other objects that support the ``__geo_interface__``.
:ref:`user-guide-generator-data` A generated dataset such as numerical sequences or geographic reference elements.
========================================= ================================================================================

When data is specified as a DataFrame, the encoding is quite simple, as Altair
joelostblom marked this conversation as resolved.
Show resolved Hide resolved
uses the data type information provided by pandas to automatically determine
the data types required in the encoding. For example, here we specify data via a pandas DataFrame
and Altair automatically detects that the x-column should be visualized on a quantitative scale
and that the y-column should be visualized on a categorical scale:

.. altair-plot::

import altair as alt
import pandas as pd

data = pd.DataFrame({'x': ['A', 'B', 'C', 'D', 'E'],
'y': [5, 3, 6, 7, 2]})
alt.Chart(data).mark_bar().encode(
x='x',
y='y',
)

mattijn marked this conversation as resolved.
Show resolved Hide resolved
If we are not happy with the scale that Altair chooses for visualizing that data,
we can change it by either changing the data types in the underlying pandas dataframe,
or by changing the :ref:`encoding-data-types` in Altair.

.. toctree::
:hidden:

dataframe
dict
url
spatial
generator
Loading