15

Observable Plot / Observable / Observable

 3 years ago
source link: https://observablehq.com/@observablehq/plot
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
Observable Plot
Published
1 file
2 collections
105 likes
athletes = FileAttachment("athletes.csv").csv({typed: true})
xxxxxxxxxx
Plot.dot(athletes, {x: "weight", y: "height", stroke: "sex"}).plot()
xxxxxxxxxx
Inputs.Table(athletes)
xxxxxxxxxx
Plot.rect(athletes, Plot.bin({fillOpacity: "count"}, {x: "weight", y: "height", fill: "sex"})).plot()
xxxxxxxxxx
Plot.rectY(athletes, Plot.binX({y: "count"}, {x: "weight", fill: "sex"})).plot()
xxxxxxxxxx
Plot.plot({
  grid: true,
  facet: {
    data: athletes,
    y: "sex"
  },
  marks: [
    Plot.rectY(athletes, Plot.binX({y: "count"}, {x: "weight", fill: "sex"})),
    Plot.ruleY([0])
  ]
})
xxxxxxxxxx
Plot = require("@observablehq/[email protected]/dist/plot.umd.min.js")
xxxxxxxxxx
d3 = require("[email protected]/dist/d3.min.js")
xxxxxxxxxx
Inputs = require("@observablehq/[email protected]/dist/inputs.umd.min.js")
xxxxxxxxxx
htl = require("[email protected]/dist/htl.min.js")
xxxxxxxxxx
function previews(notebooks, options) {
  return htl.html`<div style="display: grid; grid-gap: .875rem; grid-template-columns: repeat(auto-fill, minmax(160px, 5fr));">${notebooks.map(notebook => preview(notebook, options))}</div>`;
}
xxxxxxxxxx
function preview({path, title, author, thumbnail}, {target = "_blank"} = {}) {
  return htl.html`<a href=${`/${path}`} target=${target} title="${title}${author ? `by ${author}`: ""}" style="display: inline-flex; flex-direction: column; align-items: start; font: 400 .75rem var(--sans-serif); color: #1b1e23; width: 100%;" onmouseover=${event => event.currentTarget.firstElementChild.style.borderColor = "#1b1e23"} onmouseout=${event => event.currentTarget.firstElementChild.style.borderColor = "#e8e8e8"}>
  <div style="border: solid 1px #e8e8e8; border-radius: 4px; box-sizing: border-box; width: 100%; padding-top: 62.5%; background-size: cover; background-image: url(https://static.observableusercontent.com/thumbnail/${encodeURI(thumbnail)}.jpg);"></div>
  <div style="width: 100%; white-space: nowrap; text-overflow: ellipsis; overflow: hidden;">${title}</div>
</a>`;
}
xxxxxxxxxx
import {swatches as Swatches} from "@d3/color-legend"
xxxxxxxxxx
import {Copier} from "@mbostock/pbcopy"

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK