Platform
Resources
Pricing
Sign in
Get started
crazyorr
Workspace
Fork
Public
By
crazyorr
Edited
May 25, 2023
CC BY-SA 4.0
14
Insert cell
Insert cell
Insert cell
Insert cell
populationByPrefecture
Filter
Columns
5
Sort
Slice
Save
Type Table, then Shift-Enter. Ctrl-space for more options.
Insert cell
addTooltips
(
Plot
.
plot
(
{
x
:
{
label
:
"地级市"
}
,
y
:
{
grid
:
true
,
tickFormat
:
"s"
,
label
:
"↑ 人口数"
}
,
color
:
{
scheme
:
"spectral"
,
domain
:
genders
,
legend
:
true
}
,
marks
:
[
Plot
.
barY
(
populationByPrefectureGender
,
{
x
:
"prefecture"
,
y
:
"population"
,
fill
:
"gender"
,
title
:
"population"
,
sort
:
{
x
:
"y"
,
reverse
:
true
}
}
)
,
Plot
.
ruleY
(
[
0
]
)
]
}
)
)
Insert cell
chart
=
PieChart
(
populationByPrefecture
,
{
name
:
d
=>
d
[
"地区"
]
,
value
:
d
=>
d
[
"合计"
]
,
}
)
Insert cell
addTooltips
(
Plot
.
plot
(
{
projection
:
{
type
:
"albers"
,
rotate
:
[
-
110
,
0
]
,
domain
:
prefectures
}
,
marks
:
[
Plot
.
geo
(
prefectures
,
{
fill
:
p
=>
prefectureToPopulation
.
get
(
p
.
properties
.
fullname
)
,
title
:
p
=>
`${
p
.
properties
.
name
} \n ${
prefectureToPopulation
.
get
(
p
.
properties
.
fullname
)
.
toLocaleString
(
)
}`
}
)
]
,
margin
:
20
,
color
:
{
scheme
:
"reds"
,
// Change color scheme
unknown
:
"#ddd"
,
// Polygons with unknown values are gray
type
:
"linear"
,
// Linear scale for color progression
legend
:
true
,
// Add the legend
tickFormat
:
"s"
,
label
:
"地区人口数"
,
// Update legend label
}
}
)
)
Insert cell
addTooltips
(
Plot
.
plot
(
{
y
:
{
grid
:
true
,
tickFormat
:
d
=>
d
+
1
,
// nice: true,
label
:
"↑ 性别比(男:女)"
}
,
color
:
{
scheme
:
"PiYg"
}
,
marks
:
[
Plot
.
barY
(
populationByPrefecture
,
{
x
:
"地区"
,
y
:
d
=>
d
[
"性别比"
]
-
1
,
fill
:
d
=>
Math
.
sign
(
d
[
"性别比"
]
-
1
)
,
title
:
"性别比"
,
sort
:
{
x
:
"y"
,
reverse
:
true
}
,
}
)
,
Plot
.
ruleY
(
[
0
]
)
]
}
)
)
Insert cell
Insert cell
populationByCounty
Filter
Columns
5
Sort
Slice
Save
Type Table, then Shift-Enter. Ctrl-space for more options.
Insert cell
addTooltips
(
Plot
.
plot
(
{
projection
:
{
type
:
"albers"
,
rotate
:
[
-
110
,
0
]
,
domain
:
prefectures
}
,
marks
:
[
counties
.
map
(
county
=>
Plot
.
geo
(
county
,
{
fill
:
p
=>
countyToPopulation
.
get
(
p
.
properties
.
fullname
)
,
title
:
p
=>
{
let
name
=
p
.
properties
.
fullname
return
`${
name
} \n ${
countyToPopulation
.
get
(
name
)
.
toLocaleString
(
)
}`
}
}
)
)
,
Plot
.
geo
(
prefectures
)
,
]
,
margin
:
20
,
color
:
{
scheme
:
"reds"
,
// Change color scheme
unknown
:
"#ddd"
,
// Polygons with unknown values are gray
type
:
"linear"
,
// Linear scale for color progression
legend
:
true
,
// Add the legend
tickFormat
:
"s"
,
label
:
"地区人口数"
,
// Update legend label
}
}
)
)
Insert cell
Insert cell
Insert cell
prefectureWorkbook
=
FileAttachment
(
"地级.xlsx"
)
.
xlsx
(
)
Insert cell
populationByPrefecture
=
prefectureWorkbook
.
sheet
(
0
,
{
headers
:
true
}
)
Insert cell
prefectureToPopulation
=
new
Map
(
populationByPrefecture
.
map
(
(
{
地区
,
合计
}
)
=>
[
地区
,
合计
]
)
)
Insert cell
totalPopulation
=
populationByPrefecture
.
reduce
(
(
acc
,
cur
)
=>
acc
+
cur
[
"合计"
]
,
0
)
Insert cell
genders
=
[
"男"
,
"女"
]
Insert cell
populationByPrefectureGender
=
genders
.
flatMap
(
gender
=>
populationByPrefecture
.
map
(
d
=>
(
{
prefecture
:
d
.
地区
,
gender
,
population
:
d
[
gender
]
}
)
)
)
Insert cell
countyWorkbook
=
FileAttachment
(
"县级.xlsx"
)
.
xlsx
(
)
Insert cell
populationByCounty
=
countyWorkbook
.
sheet
(
0
,
{
headers
:
true
}
)
Insert cell
countyToPopulation
=
new
Map
(
populationByCounty
.
map
(
d
=>
[
d
.
地区
,
d
.
合计
]
)
)
Insert cell
zhejiang
=
d3
.
json
(
"https://geojson.cn/api/data/330000.topo.json"
)
Insert cell
prefectures
=
topojson
.
feature
(
zhejiang
,
zhejiang
.
objects
.
default
)
Insert cell
hangzhou
=
FileAttachment
(
"330100_2020.json"
)
.
json
(
)
Insert cell
ningbo
=
FileAttachment
(
"330200.topo.json"
)
.
json
(
)
Insert cell
wenzhou
=
FileAttachment
(
"330300.topo.json"
)
.
json
(
)
Insert cell
jiaxing
=
FileAttachment
(
"330400.topo.json"
)
.
json
(
)
Insert cell
huzhou
=
FileAttachment
(
"330500.topo.json"
)
.
json
(
)
Insert cell
shaoxing
=
FileAttachment
(
"330600.topo.json"
)
.
json
(
)
Insert cell
jinhua
=
FileAttachment
(
"330700.topo.json"
)
.
json
(
)
Insert cell
quzhou
=
FileAttachment
(
"330800.topo.json"
)
.
json
(
)
Insert cell
zhoushan
=
FileAttachment
(
"330900.topo.json"
)
.
json
(
)
Insert cell
taizhou
=
FileAttachment
(
"331000.topo.json"
)
.
json
(
)
Insert cell
lishui
=
FileAttachment
(
"331100.topo.json"
)
.
json
(
)
Insert cell
counties
=
[
hangzhou
,
ningbo
,
wenzhou
,
jiaxing
,
huzhou
,
shaoxing
,
jinhua
,
quzhou
,
zhoushan
,
taizhou
,
lishui
]
.
map
(
prefecture
=>
prefecture
.
type
===
"Topology"
?
topojson
.
feature
(
prefecture
,
prefecture
.
objects
.
default
)
:
prefecture
)
Insert cell
import
{
PieChart
}
from
"@d3/pie-chart"
Insert cell
import
{
addTooltips
}
from
"@mkfreeman/plot-tooltip"
Insert cell
Purpose-built for displays of data
Observable is your go-to platform for exploring data and creating expressive data visualizations. Use reactive JavaScript notebooks for prototyping and a collaborative canvas for visual data exploration and dashboard creation.
Try it for free
Learn more
Fork
View
Export
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
Cells
populationByPrefecture
File attachments
330600.topo.json
JSON
330400.topo.json
JSON
330700.topo.json
JSON
330500.topo.json
JSON
330800.topo.json
JSON
331100.topo.json
JSON
330900.topo.json
JSON
330300.topo.json
JSON
330200.topo.json
JSON
330100.topo.json
JSON
331000.topo.json
JSON
330100_2020.json
JSON
Databases
Filter
Column
Operator
Columns
Sort
Column
Direction
Descending
Ascending
Slice
From
Start
To
End
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
chart
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Select
Duplicate
Copy link
Embed
Delete
Cells
populationByCounty
File attachments
330600.topo.json
JSON
330400.topo.json
JSON
330700.topo.json
JSON
330500.topo.json
JSON
330800.topo.json
JSON
331100.topo.json
JSON
330900.topo.json
JSON
330300.topo.json
JSON
330200.topo.json
JSON
330100.topo.json
JSON
331000.topo.json
JSON
330100_2020.json
JSON
Databases
Filter
Column
Operator
Columns
Sort
Column
Direction
Descending
Ascending
Slice
From
Start
To
End
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Edit
Add comment
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
prefectureWorkbook
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
populationByPrefecture
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
prefectureToPopulation
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
totalPopulation
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
genders
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
populationByPrefectureGender
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
countyWorkbook
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
populationByCounty
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
countyToPopulation
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
zhejiang
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
prefectures
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
hangzhou
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
ningbo
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
wenzhou
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
jiaxing
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
huzhou
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
shaoxing
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
jinhua
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
quzhou
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
zhoushan
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
taizhou
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
lishui
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
counties
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML
Add comment
Copy import
Select
Duplicate
Copy link
Embed
Delete
JavaScript
Markdown
HTML