{
  "$type": "site.standard.document",
  "content": "---\ntitle: \"Making Altair/Vega-Lite charts readable without squinting\"\ndescription: \"A simple trick for making Altair chart text and marks bigger: set a small\n  width/height and export to SVG.\"\ntags:\n  - dev\n---\n\nMy love for the\n[Grammar of Graphics](https://www.amazon.com/Grammar-Graphics-Statistics-Computing/dp/0387245448)\nruns deep, and in particular for Hadley Wickham's famous `ggplot2` which showed\nme the light back when I was a young PhD student. Seriously, once you have your\nhead around how it works it gives you datavis superpowers. These days I often\nwork in Python, and for datavis I'm enjoying\n[Altair](https://altair-viz.github.io/index.html) which is based around the same\nphilosophy (and outputs to [Vega-Lite](https://vega.github.io/vega-lite/) for\nrendering in the browser).\n\nRecently I've needed to (a) create some snazzy graphs with Altair and (b)\ndisplay them in a slide deck. Part (a) was actually the easy part---the tricky\npart was (b) getting Altair to render charts with text & other marks that\nweren't so small that the slide was unreadable.\n\nHere's an example: a\n[simple line chart](https://altair-viz.github.io/gallery/simple_line_chart.html)\nfrom the\n[Altair Example Gallery](https://altair-viz.github.io/gallery/index.html).\n\n```python\nimport altair as alt\nimport numpy as np\nimport pandas as pd\n\nx = np.arange(100)\nsource = pd.DataFrame({\"x\": x, \"f(x)\": np.sin(x / 5)})\n\nalt.Chart(source).mark_line().encode(x=\"x\", y=\"f(x)\").save(f\"{CHART_DIR}/sin-x.svg\")\n```\n\nwhich (with default settings) produces a chart that looks like this:\n\n<p><img alt=\"f(x) = sin(x)/5\" src=\"/assets/images/posts/altair-charts/sin-x.svg\" /></p>\n\n## Easy tweaking of \"size\" through chart themes\n\nNow, that figure might look fairly readable, but when it's on a slide the text,\nlabels & even lines are quite small[^examples]. I don't need\n[fine-grained control](https://github.com/vega/vega-lite/issues/1714) over the\nrelative sizes of labels vs legend vs title, etc. I just want a simple knob for\nmaking all the text bigger so that my slides don't double as an\n[eye chart](https://en.wikipedia.org/wiki/Eye_chart). The Vega-Lite folks (the\nunderlying vis engine which Altair uses)\n[know about the issue, but don't want to fix it](https://github.com/vega/vega-parser/issues/18).\n\n:::info\n\nWhen I'm talking about \"size\" I'm **not** talking about the size & dimensions of\nthe chart---I'm talking about the size of the text, lines & other marks\n_relative to_ the overall size of the chart.\n\n:::\n\nThe easiest way I found to fix this is to set a small width & height for the\nchart, then export to a vector format (e.g. svg) so that when the image gets\ndisplayed everything will be \"stretched\" up into big, bold sizes (and since it's\na vector format, things will still be nice and crisp). This chart code is the\nsame except for the `.properties(width=100, height=60)` part:\n\n```python\nalt.Chart(source).mark_line().encode(x=\"x\", y=\"f(x)\").properties(\n    width=100, height=60\n).save(f\"{CHART_DIR}/sin-x-big-text.svg\")\n```\n\n<p><img alt=\"f(x) = sin(x)/5 with bigger labels\" src=\"/assets/images/posts/altair-charts/sin-x-big-text.svg\" /></p>\n\nObviously I'm exaggerating here to make a point, but the key point is that there\nare just a couple of numbers to tweak (`width` and `height`) which control text\n& line size, label sizes, and also titles and legends (if present). And that's\nnot something that's exposed as simply in any other way by the Altair/Vega-Lite\nAPI.\n\nOne final tip: if you want to have consistent sizes & aspect ratios across lots\nof charts (e.g. you're batch exporting lots of charts for a presentation or\nreport) you can create\n[a custom theme](https://altair-viz.github.io/user_guide/configuration.html#defining-a-custom-theme),\nbut otherwise you can just do it with a call to the `.properties()` method as\nshown.\n\n[^examples]:\n    To be honest, these simple examples from the example gallery don't really\n    help me make my point, they're still pretty readable. But when the charts\n    get more complicated & have more data marks then things get smaller & more\n    zoomed out, and the problem gets much worse.\n",
  "createdAt": "2026-05-13T23:14:57.232Z",
  "description": "A simple trick for making Altair chart text and marks bigger: set a small width/height and export to SVG.",
  "path": "/blog/2019/10/16/making-altair-vega-lite-charts-readable-without-squinting",
  "publishedAt": "2019-10-16T00:00:00.000Z",
  "site": "at://did:plc:tevykrhi4kibtsipzci76d76/site.standard.publication/self",
  "tags": [
    "dev"
  ],
  "textContent": "A simple trick for making Altair chart text and marks bigger: set a small width/height and export to SVG.",
  "title": "Making Altair/Vega-Lite charts readable without squinting"
}