File: top_k_items.py

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 (27 lines) | stat: -rw-r--r-- 668 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
"""
Top K Items
-----------
This example shows how to use the window and transformation filter to display
the Top items of a long list of items in decreasing order.
Here we sort the top 10 highest ranking movies of IMDB.
"""
# category: advanced calculations
import altair as alt
from vega_datasets import data

source = data.movies.url

# Top 10 movies by IMBD rating
alt.Chart(
    source,
).mark_bar().encode(
    alt.X('Title:N').sort('-y'),
    alt.Y('IMDB_Rating:Q'),
    alt.Color('IMDB_Rating:Q')
    
).transform_window(
    rank='rank(IMDB_Rating)',
    sort=[alt.SortField('IMDB_Rating', order='descending')]
).transform_filter(
    (alt.datum.rank < 10)
)