Skip to content

Instantly share code, notes, and snippets.

@sverhoeven
Created September 11, 2020 09:53
Show Gist options
  • Select an option

  • Save sverhoeven/25d0df5238e989215d3ac1be453a3d61 to your computer and use it in GitHub Desktop.

Select an option

Save sverhoeven/25d0df5238e989215d3ac1be453a3d61 to your computer and use it in GitHub Desktop.
newtonraphson-equation
{
"$schema": "https://vega.github.io/schema/vega-lite/v4.json",
"width": 800,
"height": 600,
"title": {"text": "2x^3 - 4x^2 + 6", "fontSize": 20, "fontWeight": "normal"},
"layer": [
{
"data": {"sequence": {"start": -4, "stop": 4, "step": 0.1, "as": "x"}},
"transform": [
{
"calculate": "2 * datum.x * datum.x * datum.x - 4 * datum.x * datum.x + 6",
"as": "y"
}
],
"mark": "line",
"selection": {"grid": {"type": "interval", "bind": "scales"}},
"encoding": {
"x": {"type": "quantitative", "field": "x", "axis":{"tickCount": 9}},
"y": {
"field": "y",
"type": "quantitative",
"scale": {"domainMin": -0.5, "domainMax": 9.5}
},
"color": {"value": "#f00"}
}
},
{
"data": {"values": [{"x": -1}]},
"encoding": {"x": {"field": "x", "type": "quantitative"}},
"layer": [
{"mark": {"type": "rule", "strokeDash": [4, 8]}},
{
"mark": {
"type": "text",
"align": "right",
"baseline": "bottom",
"dx": -4,
"dy": 10,
"x": "width",
"fontSize": 20,
"text": "root = -1.0"
}
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment