Public
Edited
Jan 3, 2023
Paused
Insert cell
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [Plot.dot(cars, { x: "power (hp)", y: "economy (mpg)" })]
})
Insert cell
cars
Insert cell
Insert cell
Insert cell
import { nycSpreadsheet } from "@observablehq/build-your-first-custom-scatterplot"
Insert cell
// 读取sheet数据并且保留表格的header
nycData = nycSpreadsheet.sheet(0, { headers: true })
Insert cell
//同样绘制一个scatterplot
Plot.plot({
marks: [Plot.dot(nycData, { x: "date", y: "medianAskingPrice" })]
})
Insert cell
Insert cell
//让某一列值作为填充值
Plot.plot({
marks: [
Plot.dot(nycData, {
x: "date",
y: "medianAskingPrice",
fill: "neighborhood", //散点填充
r: "priceCutShare" //散点大小
})
],
color: { legend: true }, //添加图例信息
marginLeft: 100
})
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.ruleY([0]),
Plot.line(nycData, {
x: "date",
y: "medianAskingPrice",
stroke: "neighborhood" //线条不闭合
}),
Plot.dot(nycData, {
x: "date",
y: "medianAskingPrice",
fill: "neighborhood",
r: "priceCutShare"
})
],
color: { legend: true },
marginLeft: 100
})
Insert cell
Insert cell
chart = Plot.plot({
facet: {
data: nycData,
y: "borough",
marginRight: 100
},
marks: [
Plot.ruleY([0]),
Plot.line(nycData, {
x: "date",
y: "medianAskingPrice",
stroke: "neighborhood" //线条不闭合
}),
Plot.dot(nycData, {
x: "date",
y: "medianAskingPrice",
fill: "neighborhood",
r: "priceCutShare"
})
],
color: { legend: true },
marginLeft: 100
})
Insert cell
Insert cell
ExportPicture({
DOM: DOM,
chart: chart,
filename: "scatterplot",
fileType: "svg"
})
Insert cell
Insert cell
import { ExportPicture } from "@zpliu1126/core"
Insert cell
import { toc } from "@nebrius/indented-toc"
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.
Learn more