Published
Edited
Nov 16, 2021
Insert cell
Insert cell
aapl = FileAttachment("aapl.csv").csv({typed: true})
Insert cell
Plot.plot({
marks: [
Plot.areaY(aapl, {x: "Date", y: "Close"})
]
})
Insert cell
Insert cell
Plot.plot({
y: {
grid: true
},
marks: [
Plot.areaY(aapl, {x: "Date", y: "Close", fill: "#ccc"}),
Plot.lineY(aapl, {x: "Date", y: "Close"}),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
numbers = d3.cumsum({length: 600}, d3.randomNormal())
Insert cell
Plot.plot({
marks: [
Plot.areaY(numbers)
]
})
Insert cell
Insert cell
Plot.plot({
y: {
grid: true
},
marks: [
Plot.areaY(d3.shuffle(aapl.slice(0, 100)), {
// sort: "Date", // uncomment to fix
x: "Date",
y: "Close"
})
]
})
Insert cell
Insert cell
sftemp = FileAttachment("sf-temperatures.csv").csv({typed: true})
Insert cell
Plot.plot({
y: {
label: "↑ Temperature (°F)",
grid: true
},
marks: [
Plot.areaY(sftemp, {x: "date", y1: "low", y2: "high"})
]
})
Insert cell
Insert cell
Plot.plot({
y: {
label: "↑ Temperature (°F)",
grid: true
},
marks: [
Plot.ruleY([32]),
Plot.areaY(sftemp, Plot.windowY({
x: "date",
y1: "low",
y2: "high",
fill: "#ccc",
k: 14
})),
Plot.line(sftemp, Plot.windowY({
x: "date",
y: d => (d.low + d.high) / 2,
k: 14
}))
]
})
Insert cell
Insert cell
Plot.plot({
x: {
label: null
},
y: {
grid: true,
reverse: true
},
marks: [
Plot.areaY(aapl, {x: "Date", y: "Close", fill: "#ccc"}),
Plot.lineY(aapl, {x: "Date", y: "Close"}),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
Plot.plot({
x: {
grid: true
},
marks: [
Plot.areaX(aapl, {y: "Date", x: "Close", fill: "#ccc"}),
Plot.lineX(aapl, {y: "Date", x: "Close"}),
Plot.ruleX([0])
]
})
Insert cell
Insert cell
someCloses = aapl.map(d => d.Date.getUTCMonth() < 3 ? NaN : d.Close)
Insert cell
Plot.plot({
y: {
grid: true
},
marks: [
Plot.areaY(aapl, {x: "Date", y: someCloses, fill: "#ccc"}),
Plot.lineY(aapl, {x: "Date", y: someCloses}),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
someAapl = aapl.filter(d => d.Date.getUTCMonth() >= 3)
Insert cell
Plot.plot({
y: {
grid: true
},
marks: [
Plot.areaY(someAapl, {x: "Date", y: "Close", fill: "#ccc"}),
Plot.lineY(someAapl, {x: "Date", y: "Close"}),
Plot.ruleY([0])
]
})
Insert cell
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.areaY(construction, {x: "date", y: "unemployed", curve, fillOpacity: 0.1}),
Plot.lineY(construction, {x: "date", y: "unemployed", curve, strokeWidth: 1}),
Plot.ruleY([0])
]
})
Insert cell
bls = FileAttachment("bls-industry-unemployment.csv").csv({typed: true})
Insert cell
construction = bls.filter(d => d.industry === "Construction")
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.areaY(bls, {x: "date", y2: "unemployed", z: "industry", fillOpacity: 0.1}),
Plot.lineY(bls, {x: "date", y: "unemployed", z: "industry", strokeWidth: 1})
]
})
Insert cell
Insert cell
Plot.plot({
marks: [
Plot.areaY(bls, {x: "date", y: "unemployed", fill: "industry"}), // implicit stacking
Plot.ruleY([0])
]
})
Insert cell
Insert cell
Plot.plot({
height: 600,
y: {
axis: null
},
fy: {
axis: "right",
label: null
},
facet: {
data: bls,
y: "industry",
marginRight: 140
},
marks: [
Plot.areaY(bls, {x: "date", y: "unemployed", fillOpacity: 0.2}),
Plot.lineY(bls, {x: "date", y: "unemployed", strokeWidth: 1})
]
})
Insert cell
Insert cell
Insert cell
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