Public
Edited
Dec 9
7 stars
Insert cell
Insert cell
Insert cell
This is a markdown cell.
Insert cell
Insert cell
1+1
Insert cell
Insert cell
year = 2022
Insert cell
We can use the variable in markdown with a dollar sign and braces: ${year}.
Insert cell
We can also define an interactive input.
Insert cell
viewof name = Inputs.text({ label: "Character", value: "Snowy" })
Insert cell
And we call this variable in the same way : ${name}.
Insert cell
Insert cell
import {get_label} from "@pac02/user-level-gender-statistics-for-wikipedia"
Insert cell
get_label("Q1640056", "en")
Insert cell
Insert cell
Insert cell
query_characters = `SELECT ?character ?characterLabel ?book ?bookLabel ?rk WHERE {
?book p:P179 ?statement.
?statement ps:P179 wd:Q744536;
pq:P1545 ?rank.
BIND(xsd:integer(?rank) AS ?rk)
?book wdt:P674 ?character.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY (?rk) (?characterLabel)`
Insert cell
data_characters = fetch(
`https://query.wikidata.org/sparql?query=${encodeURIComponent(
query_characters
)}`,
{ headers: { accept: "application/sparql-results+json" } }
).then((d) => d.json())
Insert cell
Insert cell
import {aq, op} from "@uwdata/arquero"
Insert cell
Insert cell
df_characters = aq.from(data_characters.results.bindings.map(res => ({
rank: res.rk.value,
book: res.bookLabel.value,
character: res.characterLabel.value
})))
Insert cell
Insert cell
df_characters.view()// display only the 50 first lines
Insert cell
Insert cell
df_characters
.groupby("character")
.count()
.orderby(aq.desc("count"))
.view()
Insert cell
Insert cell
Insert cell
vl.markBar()
.data(
df_characters
.groupby("character")
.count() // count by character
.orderby(aq.desc("count"))
)
.encode(
vl.y().field('character') // y axis
.type('nominal') // nominal variable. Could also be 'quantitative' or 'ordinal'
.sort("count") // sort the bars
.title("Characters of Tintin"), // y axis title
vl.x().field('count') // x-axis
.type('quantitative') // quantitative variable
.title("Number of appearances"), // title of the x-axis
vl.tooltip(['character', 'count'])
)
.width(width) // full width
.render()
Insert cell
Insert cell
viewof range = Inputs.range([0, 24], {step: 1}, {label: "Nombre d'apparitions"})
Insert cell
vl.markBar()
.data(
df_characters
.groupby("character")
.count()
.orderby(aq.desc("count"))
.filter(aq.escape(d => d.count >= range)) // add a filter
)
.encode(
vl.y().field('character')
.type('nominal')
.sort("count")
.title("Characters of Tintin"),
vl.x().field('count')
.type('quantitative')
.title("Number of appearances"),
vl.tooltip(['character', 'count'])
)
.width(width)
.render()
Insert cell
Insert cell

One platform to build and deploy the best data apps

Experiment and prototype by building visualizations in live JavaScript notebooks. Collaborate with your team and decide which concepts to build out.
Use Observable Framework to build data apps locally. Use data loaders to build in any language or library, including Python, SQL, and R.
Seamlessly deploy to Observable. Test before you ship, use automatic deploy-on-commit, and ensure your projects are always up-to-date.
Learn more