Is it possible to write Latex on Vega-Lite?

Viewed 144

I'd like to use the "text" mark with a Latex expression and plot it using Vega-Lite. Is this possible? For example:

data = {x:[0,1,2,3],y:[0,1,2,3],t=["x^0","x^1","x^2","x^3"]}
{
  "data":data
  }],
  "mark": "text",
  "encoding": {
    "x": {"field": "x", "type": "quantitative"},
    "y": {"field": "y", "type": "quantitative"},
    "text": {"field": "t", "type": "nominal"}
  }
}

1 Answers

No, Vega-Lite specifications do not support LaTeX math (the relevant feature request is here). But for simple mathematical expressions like the one in your example, you can often represent them using unicode text:

{
  "data":{
    "values": [
      {"x": 0, "t": "x⁰"},
      {"x": 1, "t": "x¹"},
      {"x": 2, "t": "x²"},
      {"x": 3, "t": "x³"}
    ]
  },
  "mark": "text",
  "encoding": {
    "x": {"field": "x", "type": "quantitative"},
    "y": {"field": "x", "type": "quantitative"},
    "text": {"field": "t", "type": "nominal"}
  }
}

enter image description here

Related