File: sample.rst

package info (click to toggle)
python-altair 5.0.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 6,952 kB
  • sloc: python: 25,649; sh: 14; makefile: 5
file content (39 lines) | stat: -rw-r--r-- 966 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
.. currentmodule:: altair

.. _user-guide-sample-transform:

Sample
~~~~~~
The sample transform is one of the simpler of all Altair's data transforms;
it takes a single parameter ``sample`` which specified a number of rows to
randomly choose from the dataset. The resulting chart will be created using
only this random subset of the data.

For example, here we chart the full cars dataset alongside a sample of 100
rows:

.. altair-plot::

   import altair as alt
   from vega_datasets import data

   source = data.cars.url

   chart = alt.Chart(source).mark_point().encode(
       x='Horsepower:Q',
       y='Miles_per_Gallon:Q',
       color='Origin:N'
   ).properties(
       width=200,
       height=200
   )

   chart | chart.transform_sample(100)


Transform Options
^^^^^^^^^^^^^^^^^
The :meth:`~Chart.transform_sample` method is built on the :class:`~SampleTransform`
class, which has the following options:

.. altair-object-table:: altair.SampleTransform