Skip to content
Vega-Lite templates

Function Plot

y = sin(x) and y = cos(x) over [-2π, 2π].

Template previewVega-Lite
Rendering…

Make it your own.

{
  "$schema": "https://vega.github.io/schema/vega-lite/v5.json",
  "data": {"sequence": {"start": -6.2832, "stop": 6.2832, "step": 0.05, "as": "x"}},
  "transform": [
    {"calculate": "sin(datum.x)", "as": "sin"},
    {"calculate": "cos(datum.x)", "as": "cos"},
    {"fold": ["sin","cos"], "as": ["fn","y"]}
  ],
  "mark": "line",
  "encoding": {
    "x": {"field": "x", "type": "quantitative", "title": "x"},
    "y": {"field": "y", "type": "quantitative", "title": "f(x)"},
    "color": {"field": "fn", "type": "nominal"}
  },
  "width": 480, "height": 240
}