{ "cells": [ { "cell_type": "code", "execution_count": 2, "id": "adf7aa23-daf2-4cfe-9910-2b00576b2ff7", "metadata": {}, "outputs": [], "source": [ "import polars as pl\n", "import altair as alt" ] }, { "cell_type": "markdown", "id": "0726aa55-4e9f-4f0f-a522-dc231c3f2c41", "metadata": {}, "source": [ "These are examples used in class, there's no additional content here, but you can see how the examples were created." ] }, { "cell_type": "code", "execution_count": 20, "id": "bb05f630-eb13-4afe-8090-dd43c2f27a47", "metadata": {}, "outputs": [], "source": [ "random_df = pl.DataFrame({\n", " \"a\": [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20],\n", " \"b\": [\"a\", \"b\", \"q\", \"c\", \"a\", \"c\", \"n\", \"c\", \"p\", \"b\", \"c\", \"n\", \"q\", \"r\", \"a\", \"b\", \"c\", \"b\", \"b\", \"b\"],\n", " \"c\": [320, 310, 300, 270, 110, 100, 130, 240, 250, 370, 330, 310, 100, 70, 210, 230, 220, 150, 160, 100]\n", "})" ] }, { "cell_type": "code", "execution_count": 21, "id": "902298fe-3a6c-446e-a060-f95071acedf1", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "<style>\n", " #altair-viz-240453dc8e7b4a848b6034958cf10567.vega-embed {\n", " width: 100%;\n", " display: flex;\n", " }\n", "\n", " #altair-viz-240453dc8e7b4a848b6034958cf10567.vega-embed details,\n", " #altair-viz-240453dc8e7b4a848b6034958cf10567.vega-embed details summary {\n", " position: relative;\n", " }\n", "</style>\n", "<div id=\"altair-viz-240453dc8e7b4a848b6034958cf10567\"></div>\n", "<script type=\"text/javascript\">\n", " var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n", " (function(spec, embedOpt){\n", " let outputDiv = document.currentScript.previousElementSibling;\n", " if (outputDiv.id !== \"altair-viz-240453dc8e7b4a848b6034958cf10567\") {\n", " outputDiv = document.getElementById(\"altair-viz-240453dc8e7b4a848b6034958cf10567\");\n", " }\n", " const paths = {\n", " \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n", " \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n", " \"vega-lite\": \"https://cdn.jsdelivr.net/npm/vega-lite@5.20.1?noext\",\n", " \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n", " };\n", "\n", " function maybeLoadScript(lib, version) {\n", " var key = `${lib.replace(\"-\", \"\")}_version`;\n", " return (VEGA_DEBUG[key] == version) ?\n", " Promise.resolve(paths[lib]) :\n", " new Promise(function(resolve, reject) {\n", " var s = document.createElement('script');\n", " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", " s.async = true;\n", " s.onload = () => {\n", " VEGA_DEBUG[key] = version;\n", " return resolve(paths[lib]);\n", " };\n", " s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n", " s.src = paths[lib];\n", " });\n", " }\n", "\n", " function showError(err) {\n", " outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n", " throw err;\n", " }\n", "\n", " function displayChart(vegaEmbed) {\n", " vegaEmbed(outputDiv, spec, embedOpt)\n", " .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n", " }\n", "\n", " if(typeof define === \"function\" && define.amd) {\n", " requirejs.config({paths});\n", " require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n", " } else {\n", " maybeLoadScript(\"vega\", \"5\")\n", " .then(() => maybeLoadScript(\"vega-lite\", \"5.20.1\"))\n", " .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n", " .catch(showError)\n", " .then(() => displayChart(vegaEmbed));\n", " }\n", " })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300}}, \"data\": {\"name\": \"data-11887e965dfb0864ae959048d77cb37f\"}, \"mark\": {\"type\": \"point\"}, \"encoding\": {\"color\": {\"field\": \"b\", \"legend\": null, \"type\": \"nominal\"}, \"fill\": {\"field\": \"b\", \"legend\": null, \"type\": \"nominal\"}, \"opacity\": {\"field\": \"b\", \"legend\": null, \"type\": \"nominal\"}, \"shape\": {\"field\": \"a\", \"legend\": null, \"type\": \"nominal\"}, \"size\": {\"field\": \"c\", \"legend\": null, \"type\": \"quantitative\"}, \"x\": {\"field\": \"a\", \"type\": \"quantitative\"}, \"y\": {\"field\": \"c\", \"type\": \"quantitative\"}}, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.20.1.json\", \"datasets\": {\"data-11887e965dfb0864ae959048d77cb37f\": [{\"a\": 1, \"b\": \"a\", \"c\": 320}, {\"a\": 2, \"b\": \"b\", \"c\": 310}, {\"a\": 3, \"b\": \"q\", \"c\": 300}, {\"a\": 4, \"b\": \"c\", \"c\": 270}, {\"a\": 5, \"b\": \"a\", \"c\": 110}, {\"a\": 6, \"b\": \"c\", \"c\": 100}, {\"a\": 7, \"b\": \"n\", \"c\": 130}, {\"a\": 8, \"b\": \"c\", \"c\": 240}, {\"a\": 9, \"b\": \"p\", \"c\": 250}, {\"a\": 10, \"b\": \"b\", \"c\": 370}, {\"a\": 11, \"b\": \"c\", \"c\": 330}, {\"a\": 12, \"b\": \"n\", \"c\": 310}, {\"a\": 13, \"b\": \"q\", \"c\": 100}, {\"a\": 14, \"b\": \"r\", \"c\": 70}, {\"a\": 15, \"b\": \"a\", \"c\": 210}, {\"a\": 16, \"b\": \"b\", \"c\": 230}, {\"a\": 17, \"b\": \"c\", \"c\": 220}, {\"a\": 18, \"b\": \"b\", \"c\": 150}, {\"a\": 19, \"b\": \"b\", \"c\": 160}, {\"a\": 20, \"b\": \"b\", \"c\": 100}]}}, {\"mode\": \"vega-lite\"});\n", "</script>" ], "text/plain": [ "alt.Chart(...)" ] }, "execution_count": 21, "metadata": {}, "output_type": "execute_result" } ], "source": [ "alt.Chart(random_df).mark_point().encode(\n", " alt.X(\"a\"),\n", " alt.Y(\"c\"),\n", " alt.Color(\"b\", legend=None),\n", " alt.Size(\"c\", legend=None),\n", " alt.Shape(\"a:N\", legend=None),\n", " alt.Fill(\"b\", legend=None),\n", " alt.Opacity(\"b\", legend=None),\n", ") " ] }, { "cell_type": "code", "execution_count": null, "id": "87228f27-baad-4acb-80af-1ca44c21e8fe", "metadata": {}, "outputs": [], "source": [] }, { "cell_type": "code", "execution_count": 19, "id": "5515ea60-70c1-4fd7-bef9-b5451c2ea00c", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "<style>\n", " #altair-viz-3cb4232660b6443eaf01ad5947f54289.vega-embed {\n", " width: 100%;\n", " display: flex;\n", " }\n", "\n", " #altair-viz-3cb4232660b6443eaf01ad5947f54289.vega-embed details,\n", " #altair-viz-3cb4232660b6443eaf01ad5947f54289.vega-embed details summary {\n", " position: relative;\n", " }\n", "</style>\n", "<div id=\"altair-viz-3cb4232660b6443eaf01ad5947f54289\"></div>\n", "<script type=\"text/javascript\">\n", " var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n", " (function(spec, embedOpt){\n", " let outputDiv = document.currentScript.previousElementSibling;\n", " if (outputDiv.id !== \"altair-viz-3cb4232660b6443eaf01ad5947f54289\") {\n", " outputDiv = document.getElementById(\"altair-viz-3cb4232660b6443eaf01ad5947f54289\");\n", " }\n", " const paths = {\n", " \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n", " \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n", " \"vega-lite\": \"https://cdn.jsdelivr.net/npm/vega-lite@5.20.1?noext\",\n", " \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n", " };\n", "\n", " function maybeLoadScript(lib, version) {\n", " var key = `${lib.replace(\"-\", \"\")}_version`;\n", " return (VEGA_DEBUG[key] == version) ?\n", " Promise.resolve(paths[lib]) :\n", " new Promise(function(resolve, reject) {\n", " var s = document.createElement('script');\n", " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", " s.async = true;\n", " s.onload = () => {\n", " VEGA_DEBUG[key] = version;\n", " return resolve(paths[lib]);\n", " };\n", " s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n", " s.src = paths[lib];\n", " });\n", " }\n", "\n", " function showError(err) {\n", " outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n", " throw err;\n", " }\n", "\n", " function displayChart(vegaEmbed) {\n", " vegaEmbed(outputDiv, spec, embedOpt)\n", " .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n", " }\n", "\n", " if(typeof define === \"function\" && define.amd) {\n", " requirejs.config({paths});\n", " require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n", " } else {\n", " maybeLoadScript(\"vega\", \"5\")\n", " .then(() => maybeLoadScript(\"vega-lite\", \"5.20.1\"))\n", " .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n", " .catch(showError)\n", " .then(() => displayChart(vegaEmbed));\n", " }\n", " })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300}}, \"data\": {\"name\": \"data-06c45c95ede5c7f29698daa415db1c71\"}, \"mark\": {\"type\": \"line\"}, \"encoding\": {\"x\": {\"field\": \"a\", \"type\": \"quantitative\"}, \"y\": {\"field\": \"c\", \"type\": \"quantitative\"}}, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.20.1.json\", \"datasets\": {\"data-06c45c95ede5c7f29698daa415db1c71\": [{\"a\": 1, \"b\": \"a\", \"c\": 500}, {\"a\": 2, \"b\": \"b\", \"c\": 430}, {\"a\": 3, \"b\": \"q\", \"c\": 300}, {\"a\": 4, \"b\": \"c\", \"c\": 270}, {\"a\": 5, \"b\": \"a\", \"c\": 110}, {\"a\": 6, \"b\": \"c\", \"c\": 100}, {\"a\": 7, \"b\": \"n\", \"c\": 130}, {\"a\": 8, \"b\": \"c\", \"c\": 240}, {\"a\": 9, \"b\": \"p\", \"c\": 250}, {\"a\": 10, \"b\": \"b\", \"c\": 370}, {\"a\": 11, \"b\": \"c\", \"c\": 330}, {\"a\": 12, \"b\": \"n\", \"c\": 310}, {\"a\": 13, \"b\": \"q\", \"c\": 100}, {\"a\": 14, \"b\": \"r\", \"c\": 70}, {\"a\": 15, \"b\": \"a\", \"c\": 210}, {\"a\": 16, \"b\": \"b\", \"c\": 230}, {\"a\": 17, \"b\": \"c\", \"c\": 220}, {\"a\": 18, \"b\": \"b\", \"c\": 150}, {\"a\": 19, \"b\": \"b\", \"c\": 160}, {\"a\": 20, \"b\": \"b\", \"c\": 100}]}}, {\"mode\": \"vega-lite\"});\n", "</script>" ], "text/plain": [ "alt.Chart(...)" ] }, "execution_count": 19, "metadata": {}, "output_type": "execute_result" } ], "source": [ "alt.Chart(random_df).mark_line().encode(\n", " x=\"a\",\n", " y=\"c\",\n", ")" ] }, { "cell_type": "code", "execution_count": 143, "id": "ba3df4b2-e64e-4574-b104-068ebe8d76c2", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "<style>\n", " #altair-viz-84136455ba564453b622f5b7d324ad44.vega-embed {\n", " width: 100%;\n", " display: flex;\n", " }\n", "\n", " #altair-viz-84136455ba564453b622f5b7d324ad44.vega-embed details,\n", " #altair-viz-84136455ba564453b622f5b7d324ad44.vega-embed details summary {\n", " position: relative;\n", " }\n", "</style>\n", "<div id=\"altair-viz-84136455ba564453b622f5b7d324ad44\"></div>\n", "<script type=\"text/javascript\">\n", " var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n", " (function(spec, embedOpt){\n", " let outputDiv = document.currentScript.previousElementSibling;\n", " if (outputDiv.id !== \"altair-viz-84136455ba564453b622f5b7d324ad44\") {\n", " outputDiv = document.getElementById(\"altair-viz-84136455ba564453b622f5b7d324ad44\");\n", " }\n", " const paths = {\n", " \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n", " \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n", " \"vega-lite\": \"https://cdn.jsdelivr.net/npm/vega-lite@5.20.1?noext\",\n", " \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n", " };\n", "\n", " function maybeLoadScript(lib, version) {\n", " var key = `${lib.replace(\"-\", \"\")}_version`;\n", " return (VEGA_DEBUG[key] == version) ?\n", " Promise.resolve(paths[lib]) :\n", " new Promise(function(resolve, reject) {\n", " var s = document.createElement('script');\n", " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", " s.async = true;\n", " s.onload = () => {\n", " VEGA_DEBUG[key] = version;\n", " return resolve(paths[lib]);\n", " };\n", " s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n", " s.src = paths[lib];\n", " });\n", " }\n", "\n", " function showError(err) {\n", " outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n", " throw err;\n", " }\n", "\n", " function displayChart(vegaEmbed) {\n", " vegaEmbed(outputDiv, spec, embedOpt)\n", " .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n", " }\n", "\n", " if(typeof define === \"function\" && define.amd) {\n", " requirejs.config({paths});\n", " require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n", " } else {\n", " maybeLoadScript(\"vega\", \"5\")\n", " .then(() => maybeLoadScript(\"vega-lite\", \"5.20.1\"))\n", " .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n", " .catch(showError)\n", " .then(() => displayChart(vegaEmbed));\n", " }\n", " })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300}}, \"layer\": [{\"mark\": {\"type\": \"line\"}, \"encoding\": {\"color\": {\"field\": \"category\", \"legend\": null, \"type\": \"nominal\"}, \"x\": {\"field\": \"delta-stimulus\", \"type\": \"quantitative\"}, \"y\": {\"field\": \"response\", \"type\": \"quantitative\"}}}, {\"mark\": {\"type\": \"text\", \"align\": \"left\", \"dx\": 2}, \"encoding\": {\"color\": {\"field\": \"category\", \"type\": \"nominal\"}, \"text\": {\"field\": \"category\", \"type\": \"nominal\"}, \"x\": {\"aggregate\": \"max\", \"field\": \"delta-stimulus\", \"type\": \"quantitative\"}, \"y\": {\"aggregate\": \"max\", \"field\": \"response\", \"type\": \"quantitative\"}}}], \"data\": {\"name\": \"data-e83bb7e1867358e82dcb2f51a5487998\"}, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.20.1.json\", \"datasets\": {\"data-e83bb7e1867358e82dcb2f51a5487998\": [{\"category\": \"brightness\", \"delta-stimulus\": 0.0, \"response\": 0.0}, {\"category\": \"depth perception\", \"delta-stimulus\": 0.0, \"response\": 0.0}, {\"category\": \"area\", \"delta-stimulus\": 0.0, \"response\": 0.0}, {\"category\": \"2D position\", \"delta-stimulus\": 0.0, \"response\": 0.0}, {\"category\": \"color saturation\", \"delta-stimulus\": 0.0, \"response\": 0.0}, {\"category\": \"brightness\", \"delta-stimulus\": 0.2, \"response\": 0.5253055608807534}, {\"category\": \"depth perception\", \"delta-stimulus\": 0.2, \"response\": 0.36278464514424597}, {\"category\": \"area\", \"delta-stimulus\": 0.2, \"response\": 0.32413131933855255}, {\"category\": \"2D position\", \"delta-stimulus\": 0.2, \"response\": 0.2}, {\"category\": \"color saturation\", \"delta-stimulus\": 0.2, \"response\": 0.06482626386771051}, {\"category\": \"brightness\", \"delta-stimulus\": 0.4, \"response\": 0.6931448431551464}, {\"category\": \"depth perception\", \"delta-stimulus\": 0.4, \"response\": 0.5614328170199332}, {\"category\": \"area\", \"delta-stimulus\": 0.4, \"response\": 0.526552881733695}, {\"category\": \"2D position\", \"delta-stimulus\": 0.4, \"response\": 0.4}, {\"category\": \"color saturation\", \"delta-stimulus\": 0.4, \"response\": 0.210621152693478}, {\"category\": \"brightness\", \"delta-stimulus\": 0.6, \"response\": 0.8151931096059227}, {\"category\": \"depth perception\", \"delta-stimulus\": 0.6, \"response\": 0.7248285441143673}, {\"category\": \"area\", \"delta-stimulus\": 0.6, \"response\": 0.6993681904144294}, {\"category\": \"2D position\", \"delta-stimulus\": 0.6, \"response\": 0.6}, {\"category\": \"color saturation\", \"delta-stimulus\": 0.6, \"response\": 0.41962091424865766}, {\"category\": \"brightness\", \"delta-stimulus\": 0.8, \"response\": 0.9146101038546527}, {\"category\": \"depth perception\", \"delta-stimulus\": 0.8, \"response\": 0.8688537738459388}, {\"category\": \"area\", \"delta-stimulus\": 0.8, \"response\": 0.8553876799929505}, {\"category\": \"2D position\", \"delta-stimulus\": 0.8, \"response\": 0.8}, {\"category\": \"color saturation\", \"delta-stimulus\": 0.8, \"response\": 0.6843101439943604}, {\"category\": \"brightness\", \"delta-stimulus\": 1.0, \"response\": 1.0}, {\"category\": \"depth perception\", \"delta-stimulus\": 1.0, \"response\": 1.0}, {\"category\": \"area\", \"delta-stimulus\": 1.0, \"response\": 1.0}, {\"category\": \"2D position\", \"delta-stimulus\": 1.0, \"response\": 1.0}, {\"category\": \"color saturation\", \"delta-stimulus\": 1.0, \"response\": 1.0}, {\"category\": \"brightness\", \"delta-stimulus\": 1.25, \"response\": 1.0933620739432781}, {\"category\": \"depth perception\", \"delta-stimulus\": 1.25, \"response\": 1.150941654512875}, {\"category\": \"area\", \"delta-stimulus\": 1.25, \"response\": 1.1690605597782766}, {\"category\": \"2D position\", \"delta-stimulus\": 1.25, \"response\": 1.25}, {\"category\": \"color saturation\", \"delta-stimulus\": 1.25, \"response\": 1.4613256997228459}, {\"category\": \"brightness\", \"delta-stimulus\": 1.5, \"response\": 1.1760790225246736}, {\"category\": \"depth perception\", \"delta-stimulus\": 1.5, \"response\": 1.291033445393757}, {\"category\": \"area\", \"delta-stimulus\": 1.5, \"response\": 1.328201239943334}, {\"category\": \"2D position\", \"delta-stimulus\": 1.5, \"response\": 1.5}, {\"category\": \"color saturation\", \"delta-stimulus\": 1.5, \"response\": 1.9923018599150013}, {\"category\": \"brightness\", \"delta-stimulus\": 1.75, \"response\": 1.2508787635704217}, {\"category\": \"depth perception\", \"delta-stimulus\": 1.75, \"response\": 1.422702093823748}, {\"category\": \"area\", \"delta-stimulus\": 1.75, \"response\": 1.4795397379753739}, {\"category\": \"2D position\", \"delta-stimulus\": 1.75, \"response\": 1.75}, {\"category\": \"color saturation\", \"delta-stimulus\": 1.75, \"response\": 2.589194541456904}, {\"category\": \"brightness\", \"delta-stimulus\": 2.0, \"response\": 1.3195079107728942}, {\"category\": \"depth perception\", \"delta-stimulus\": 2.0, \"response\": 1.5475649935423899}, {\"category\": \"area\", \"delta-stimulus\": 2.0, \"response\": 1.624504792712471}, {\"category\": \"2D position\", \"delta-stimulus\": 2.0, \"response\": 2.0}, {\"category\": \"color saturation\", \"delta-stimulus\": 2.0, \"response\": 3.249009585424942}, {\"category\": \"brightness\", \"delta-stimulus\": 3.0, \"response\": 1.5518455739153598}, {\"category\": \"depth perception\", \"delta-stimulus\": 3.0, \"response\": 1.9979581655837992}, {\"category\": \"area\", \"delta-stimulus\": 3.0, \"response\": 2.157669279974593}, {\"category\": \"2D position\", \"delta-stimulus\": 3.0, \"response\": 3.0}, {\"category\": \"color saturation\", \"delta-stimulus\": 3.0, \"response\": 6.473007839923779}]}}, {\"mode\": \"vega-lite\"});\n", "</script>" ], "text/plain": [ "alt.LayerChart(...)" ] }, "execution_count": 143, "metadata": {}, "output_type": "execute_result" } ], "source": [ "stevens = {\"brightness\": 0.4, \"depth perception\": 0.63, \"area\": 0.7, \"2D position\": 1, \n", " \"color saturation\": 1.7, \n", " # \"electric shock\": 3.5\n", " }\n", "\n", "rows = []\n", "for x in [0,0.2,0.4,0.6, 0.8, 1.0, 1.25, 1.5, 1.75, 2, 3]:\n", " for cat, exponent in stevens.items():\n", " rows.append({\"category\": cat, \"delta-stimulus\": x, \"response\": x**exponent})\n", "\n", "stevens_df = pl.DataFrame(rows)\n", "\n", "alt.Chart(stevens_df).mark_line().encode(\n", " alt.Color(\"category\", legend=None),\n", " alt.X(\"delta-stimulus\"),\n", " alt.Y(\"response\"),\n", ") + alt.Chart(stevens_df).mark_text(align=\"left\", dx=2).encode(\n", " alt.Color(\"category\"),\n", " alt.Text(\"category\"),\n", " alt.X(\"delta-stimulus\", aggregate=\"max\"),\n", " alt.Y(\"response\", aggregate=\"max\"),\n", ").properties()" ] }, { "cell_type": "code", "execution_count": 138, "id": "95dc101c-1dda-413a-87fb-b700fe5f43e3", "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "<style>\n", " #altair-viz-bc53670734f24e488b34439eb87105b4.vega-embed {\n", " width: 100%;\n", " display: flex;\n", " }\n", "\n", " #altair-viz-bc53670734f24e488b34439eb87105b4.vega-embed details,\n", " #altair-viz-bc53670734f24e488b34439eb87105b4.vega-embed details summary {\n", " position: relative;\n", " }\n", "</style>\n", "<div id=\"altair-viz-bc53670734f24e488b34439eb87105b4\"></div>\n", "<script type=\"text/javascript\">\n", " var VEGA_DEBUG = (typeof VEGA_DEBUG == \"undefined\") ? {} : VEGA_DEBUG;\n", " (function(spec, embedOpt){\n", " let outputDiv = document.currentScript.previousElementSibling;\n", " if (outputDiv.id !== \"altair-viz-bc53670734f24e488b34439eb87105b4\") {\n", " outputDiv = document.getElementById(\"altair-viz-bc53670734f24e488b34439eb87105b4\");\n", " }\n", " const paths = {\n", " \"vega\": \"https://cdn.jsdelivr.net/npm/vega@5?noext\",\n", " \"vega-lib\": \"https://cdn.jsdelivr.net/npm/vega-lib?noext\",\n", " \"vega-lite\": \"https://cdn.jsdelivr.net/npm/vega-lite@5.20.1?noext\",\n", " \"vega-embed\": \"https://cdn.jsdelivr.net/npm/vega-embed@6?noext\",\n", " };\n", "\n", " function maybeLoadScript(lib, version) {\n", " var key = `${lib.replace(\"-\", \"\")}_version`;\n", " return (VEGA_DEBUG[key] == version) ?\n", " Promise.resolve(paths[lib]) :\n", " new Promise(function(resolve, reject) {\n", " var s = document.createElement('script');\n", " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", " s.async = true;\n", " s.onload = () => {\n", " VEGA_DEBUG[key] = version;\n", " return resolve(paths[lib]);\n", " };\n", " s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n", " s.src = paths[lib];\n", " });\n", " }\n", "\n", " function showError(err) {\n", " outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n", " throw err;\n", " }\n", "\n", " function displayChart(vegaEmbed) {\n", " vegaEmbed(outputDiv, spec, embedOpt)\n", " .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n", " }\n", "\n", " if(typeof define === \"function\" && define.amd) {\n", " requirejs.config({paths});\n", " require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n", " } else {\n", " maybeLoadScript(\"vega\", \"5\")\n", " .then(() => maybeLoadScript(\"vega-lite\", \"5.20.1\"))\n", " .then(() => maybeLoadScript(\"vega-embed\", \"6\"))\n", " .catch(showError)\n", " .then(() => displayChart(vegaEmbed));\n", " }\n", " })({\"config\": {\"view\": {\"continuousWidth\": 300, \"continuousHeight\": 300}}, \"data\": {\"name\": \"data-0e90517b784600bf101c0511aa54d2f3\"}, \"mark\": {\"type\": \"text\", \"align\": \"left\", \"dx\": 0}, \"encoding\": {\"color\": {\"field\": \"category\", \"type\": \"nominal\"}, \"text\": {\"field\": \"category\", \"type\": \"nominal\"}, \"x\": {\"aggregate\": \"max\", \"field\": \"delta-stimulus\", \"type\": \"quantitative\"}, \"y\": {\"aggregate\": \"max\", \"field\": \"response\", \"type\": \"quantitative\"}}, \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.20.1.json\", \"datasets\": {\"data-0e90517b784600bf101c0511aa54d2f3\": [{\"category\": \"brightness\", \"delta-stimulus\": 0.0, \"response\": 0.0}, {\"category\": \"depth perception\", \"delta-stimulus\": 0.0, \"response\": 0.0}, {\"category\": \"area\", \"delta-stimulus\": 0.0, \"response\": 0.0}, {\"category\": \"2D position\", \"delta-stimulus\": 0.0, \"response\": 0.0}, {\"category\": \"color saturation\", \"delta-stimulus\": 0.0, \"response\": 0.0}, {\"category\": \"brightness\", \"delta-stimulus\": 0.2, \"response\": 0.5253055608807534}, {\"category\": \"depth perception\", \"delta-stimulus\": 0.2, \"response\": 0.34016536861678487}, {\"category\": \"area\", \"delta-stimulus\": 0.2, \"response\": 0.32413131933855255}, {\"category\": \"2D position\", \"delta-stimulus\": 0.2, \"response\": 0.2}, {\"category\": \"color saturation\", \"delta-stimulus\": 0.2, \"response\": 0.06482626386771051}, {\"category\": \"brightness\", \"delta-stimulus\": 0.4, \"response\": 0.6931448431551464}, {\"category\": \"depth perception\", \"delta-stimulus\": 0.4, \"response\": 0.5412279224891856}, {\"category\": \"area\", \"delta-stimulus\": 0.4, \"response\": 0.526552881733695}, {\"category\": \"2D position\", \"delta-stimulus\": 0.4, \"response\": 0.4}, {\"category\": \"color saturation\", \"delta-stimulus\": 0.4, \"response\": 0.210621152693478}, {\"category\": \"brightness\", \"delta-stimulus\": 0.6, \"response\": 0.8151931096059227}, {\"category\": \"depth perception\", \"delta-stimulus\": 0.6, \"response\": 0.7101683900920394}, {\"category\": \"area\", \"delta-stimulus\": 0.6, \"response\": 0.6993681904144294}, {\"category\": \"2D position\", \"delta-stimulus\": 0.6, \"response\": 0.6}, {\"category\": \"color saturation\", \"delta-stimulus\": 0.6, \"response\": 0.41962091424865766}, {\"category\": \"brightness\", \"delta-stimulus\": 0.8, \"response\": 0.9146101038546527}, {\"category\": \"depth perception\", \"delta-stimulus\": 0.8, \"response\": 0.8611331167340528}, {\"category\": \"area\", \"delta-stimulus\": 0.8, \"response\": 0.8553876799929505}, {\"category\": \"2D position\", \"delta-stimulus\": 0.8, \"response\": 0.8}, {\"category\": \"color saturation\", \"delta-stimulus\": 0.8, \"response\": 0.6843101439943604}, {\"category\": \"brightness\", \"delta-stimulus\": 1.0, \"response\": 1.0}, {\"category\": \"depth perception\", \"delta-stimulus\": 1.0, \"response\": 1.0}, {\"category\": \"area\", \"delta-stimulus\": 1.0, \"response\": 1.0}, {\"category\": \"2D position\", \"delta-stimulus\": 1.0, \"response\": 1.0}, {\"category\": \"color saturation\", \"delta-stimulus\": 1.0, \"response\": 1.0}, {\"category\": \"brightness\", \"delta-stimulus\": 1.25, \"response\": 1.0933620739432781}, {\"category\": \"depth perception\", \"delta-stimulus\": 1.25, \"response\": 1.1612606466612456}, {\"category\": \"area\", \"delta-stimulus\": 1.25, \"response\": 1.1690605597782766}, {\"category\": \"2D position\", \"delta-stimulus\": 1.25, \"response\": 1.25}, {\"category\": \"color saturation\", \"delta-stimulus\": 1.25, \"response\": 1.4613256997228459}, {\"category\": \"brightness\", \"delta-stimulus\": 1.5, \"response\": 1.1760790225246736}, {\"category\": \"depth perception\", \"delta-stimulus\": 1.5, \"response\": 1.312142926451156}, {\"category\": \"area\", \"delta-stimulus\": 1.5, \"response\": 1.328201239943334}, {\"category\": \"2D position\", \"delta-stimulus\": 1.5, \"response\": 1.5}, {\"category\": \"color saturation\", \"delta-stimulus\": 1.5, \"response\": 1.9923018599150013}, {\"category\": \"brightness\", \"delta-stimulus\": 1.75, \"response\": 1.2508787635704217}, {\"category\": \"depth perception\", \"delta-stimulus\": 1.75, \"response\": 1.4549078683787613}, {\"category\": \"area\", \"delta-stimulus\": 1.75, \"response\": 1.4795397379753739}, {\"category\": \"2D position\", \"delta-stimulus\": 1.75, \"response\": 1.75}, {\"category\": \"color saturation\", \"delta-stimulus\": 1.75, \"response\": 2.589194541456904}, {\"category\": \"brightness\", \"delta-stimulus\": 2.0, \"response\": 1.3195079107728942}, {\"category\": \"depth perception\", \"delta-stimulus\": 2.0, \"response\": 1.5910729675098374}, {\"category\": \"area\", \"delta-stimulus\": 2.0, \"response\": 1.624504792712471}, {\"category\": \"2D position\", \"delta-stimulus\": 2.0, \"response\": 2.0}, {\"category\": \"color saturation\", \"delta-stimulus\": 2.0, \"response\": 3.249009585424942}, {\"category\": \"brightness\", \"delta-stimulus\": 3.0, \"response\": 1.5518455739153598}, {\"category\": \"depth perception\", \"delta-stimulus\": 3.0, \"response\": 2.087715139785683}, {\"category\": \"area\", \"delta-stimulus\": 3.0, \"response\": 2.157669279974593}, {\"category\": \"2D position\", \"delta-stimulus\": 3.0, \"response\": 3.0}, {\"category\": \"color saturation\", \"delta-stimulus\": 3.0, \"response\": 6.473007839923779}]}}, {\"mode\": \"vega-lite\"});\n", "</script>" ], "text/plain": [ "alt.Chart(...)" ] }, "execution_count": 138, "metadata": {}, "output_type": "execute_result" } ], "source": [ "\n" ] }, { "cell_type": "code", "execution_count": null, "id": "9ad736e1-0e19-46d1-8e93-2b1409ffffc1", "metadata": {}, "outputs": [], "source": [] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.10.15" } }, "nbformat": 4, "nbformat_minor": 5 }