Published unlisted
Edited
Jul 13, 2021
Insert cell
md`# Testing Plot with SP500`

Insert cell
sp500 = FileAttachment("sp500.csv").csv({typed: true})
Insert cell
Added in fork
data = sp500.map(d => {
return {
...d,
date: parser(d.date)
}
})
Insert cell
md`### Format date accordingly, MMM day YYYY`
Insert cell
parser = d3.timeParse("%b %d %Y")

Insert cell
md`### Get first and last array for date`
Insert cell
startDate = parser(sp500[0].date)
Insert cell
endDate = parser(sp500[122].date)
Insert cell
md`### Format X axis labels`
Insert cell
Plot.plot( {x: {type: "time", domain: [startDate, endDate]}, grid: true})
Insert cell
md` ## x-axis dates too close to each other`
Insert cell
Changed in fork
-
Plot.dot(sp500, { x: "date", y: "price", stroke:"price" }).plot({
+
Plot.dot(data, { x: "date", y: "price", stroke:"price" }).plot({
width:1200, height: 600, grid: true, inset: 10, y: { label: "Price", padding: 0.1 }, x: { label: "Month", padding: 0.1, }, })
Insert cell
md` ### How to format date in month?`
Insert cell
Plot.plot({
grid: true,
width:1200,
height: 600,
marks: [
Plot.ruleY([0]),
Plot.dot(sp500, {x: {type: "time", domain: [startDate, endDate]}, y: "price", stroke: "price"})
]
})
Insert cell