178 lines
31 KiB
Plaintext
178 lines
31 KiB
Plaintext
{
|
|
"cells": [
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": 43,
|
|
"id": "4a015e87-cf20-47b0-b271-a9dc1c38f2b3",
|
|
"metadata": {},
|
|
"outputs": [
|
|
{
|
|
"data": {
|
|
"text/html": [
|
|
"\n",
|
|
"<style>\n",
|
|
" #altair-viz-6e4fea272d6f4342b396f5d5f1715ba6.vega-embed {\n",
|
|
" width: 100%;\n",
|
|
" display: flex;\n",
|
|
" }\n",
|
|
"\n",
|
|
" #altair-viz-6e4fea272d6f4342b396f5d5f1715ba6.vega-embed details,\n",
|
|
" #altair-viz-6e4fea272d6f4342b396f5d5f1715ba6.vega-embed details summary {\n",
|
|
" position: relative;\n",
|
|
" }\n",
|
|
"</style>\n",
|
|
"<div id=\"altair-viz-6e4fea272d6f4342b396f5d5f1715ba6\"></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-6e4fea272d6f4342b396f5d5f1715ba6\") {\n",
|
|
" outputDiv = document.getElementById(\"altair-viz-6e4fea272d6f4342b396f5d5f1715ba6\");\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\": [{\"data\": {\"name\": \"data-01eed797016d7a820140a15818a43ac7\"}, \"mark\": {\"type\": \"line\"}, \"encoding\": {\"color\": {\"field\": \"symbol\", \"type\": \"nominal\"}, \"x\": {\"field\": \"date\", \"type\": \"temporal\"}, \"y\": {\"field\": \"price\", \"type\": \"quantitative\"}}}, {\"data\": {\"name\": \"empty\"}, \"mark\": {\"type\": \"text\", \"color\": \"black\", \"dx\": -45, \"dy\": -130}, \"encoding\": {\"text\": {\"datum\": \"iPhone Released\"}, \"x\": {\"datum\": {\"month\": \"June\", \"year\": 2007}}}}, {\"data\": {\"name\": \"empty\"}, \"mark\": {\"type\": \"rule\", \"color\": \"black\", \"strokeWidth\": 1}, \"encoding\": {\"x\": {\"datum\": {\"month\": \"June\", \"year\": 2007}}}}, {\"data\": {\"name\": \"empty\"}, \"mark\": {\"type\": \"text\", \"color\": \"black\", \"dx\": 45, \"dy\": 60}, \"encoding\": {\"text\": {\"datum\": \"2008 Financial Crisis\"}, \"x\": {\"datum\": {\"month\": \"November\", \"year\": 2008}}}}, {\"data\": {\"name\": \"empty\"}, \"mark\": {\"type\": \"rect\", \"color\": \"#cccccc33\"}, \"encoding\": {\"text\": {\"datum\": \"2008 Financial Crisis\"}, \"x\": {\"datum\": {\"month\": \"January\", \"year\": 2008}}, \"x2\": {\"datum\": {\"month\": \"January\", \"year\": 2009}}}}], \"$schema\": \"https://vega.github.io/schema/vega-lite/v5.20.1.json\", \"datasets\": {\"data-01eed797016d7a820140a15818a43ac7\": [{\"symbol\": \"MSFT\", \"date\": \"2005-02-01T00:00:00\", \"price\": 23.15}, {\"symbol\": \"MSFT\", \"date\": \"2005-03-01T00:00:00\", \"price\": 22.24}, {\"symbol\": \"MSFT\", \"date\": \"2005-04-01T00:00:00\", \"price\": 23.28}, {\"symbol\": \"MSFT\", \"date\": \"2005-05-01T00:00:00\", \"price\": 23.82}, {\"symbol\": \"MSFT\", \"date\": \"2005-06-01T00:00:00\", \"price\": 22.93}, {\"symbol\": \"MSFT\", \"date\": \"2005-07-01T00:00:00\", \"price\": 23.64}, {\"symbol\": \"MSFT\", \"date\": \"2005-08-01T00:00:00\", \"price\": 25.35}, {\"symbol\": \"MSFT\", \"date\": \"2005-09-01T00:00:00\", \"price\": 23.83}, {\"symbol\": \"MSFT\", \"date\": \"2005-10-01T00:00:00\", \"price\": 23.8}, {\"symbol\": \"MSFT\", \"date\": \"2005-11-01T00:00:00\", \"price\": 25.71}, {\"symbol\": \"MSFT\", \"date\": \"2005-12-01T00:00:00\", \"price\": 24.29}, {\"symbol\": \"MSFT\", \"date\": \"2006-01-01T00:00:00\", \"price\": 26.14}, {\"symbol\": \"MSFT\", \"date\": \"2006-02-01T00:00:00\", \"price\": 25.04}, {\"symbol\": \"MSFT\", \"date\": \"2006-03-01T00:00:00\", \"price\": 25.36}, {\"symbol\": \"MSFT\", \"date\": \"2006-04-01T00:00:00\", \"price\": 22.5}, {\"symbol\": \"MSFT\", \"date\": \"2006-05-01T00:00:00\", \"price\": 21.19}, {\"symbol\": \"MSFT\", \"date\": \"2006-06-01T00:00:00\", \"price\": 21.8}, {\"symbol\": \"MSFT\", \"date\": \"2006-07-01T00:00:00\", \"price\": 22.51}, {\"symbol\": \"MSFT\", \"date\": \"2006-08-01T00:00:00\", \"price\": 24.13}, {\"symbol\": \"MSFT\", \"date\": \"2006-09-01T00:00:00\", \"price\": 25.68}, {\"symbol\": \"MSFT\", \"date\": \"2006-10-01T00:00:00\", \"price\": 26.96}, {\"symbol\": \"MSFT\", \"date\": \"2006-11-01T00:00:00\", \"price\": 27.66}, {\"symbol\": \"MSFT\", \"date\": \"2006-12-01T00:00:00\", \"price\": 28.13}, {\"symbol\": \"MSFT\", \"date\": \"2007-01-01T00:00:00\", \"price\": 29.07}, {\"symbol\": \"MSFT\", \"date\": \"2007-02-01T00:00:00\", \"price\": 26.63}, {\"symbol\": \"MSFT\", \"date\": \"2007-03-01T00:00:00\", \"price\": 26.35}, {\"symbol\": \"MSFT\", \"date\": \"2007-04-01T00:00:00\", \"price\": 28.3}, {\"symbol\": \"MSFT\", \"date\": \"2007-05-01T00:00:00\", \"price\": 29.11}, {\"symbol\": \"MSFT\", \"date\": \"2007-06-01T00:00:00\", \"price\": 27.95}, {\"symbol\": \"MSFT\", \"date\": \"2007-07-01T00:00:00\", \"price\": 27.5}, {\"symbol\": \"MSFT\", \"date\": \"2007-08-01T00:00:00\", \"price\": 27.34}, {\"symbol\": \"MSFT\", \"date\": \"2007-09-01T00:00:00\", \"price\": 28.04}, {\"symbol\": \"MSFT\", \"date\": \"2007-10-01T00:00:00\", \"price\": 35.03}, {\"symbol\": \"MSFT\", \"date\": \"2007-11-01T00:00:00\", \"price\": 32.09}, {\"symbol\": \"MSFT\", \"date\": \"2007-12-01T00:00:00\", \"price\": 34.0}, {\"symbol\": \"MSFT\", \"date\": \"2008-01-01T00:00:00\", \"price\": 31.13}, {\"symbol\": \"MSFT\", \"date\": \"2008-02-01T00:00:00\", \"price\": 26.07}, {\"symbol\": \"MSFT\", \"date\": \"2008-03-01T00:00:00\", \"price\": 27.21}, {\"symbol\": \"MSFT\", \"date\": \"2008-04-01T00:00:00\", \"price\": 27.34}, {\"symbol\": \"MSFT\", \"date\": \"2008-05-01T00:00:00\", \"price\": 27.25}, {\"symbol\": \"MSFT\", \"date\": \"2008-06-01T00:00:00\", \"price\": 26.47}, {\"symbol\": \"MSFT\", \"date\": \"2008-07-01T00:00:00\", \"price\": 24.75}, {\"symbol\": \"MSFT\", \"date\": \"2008-08-01T00:00:00\", \"price\": 26.36}, {\"symbol\": \"MSFT\", \"date\": \"2008-09-01T00:00:00\", \"price\": 25.78}, {\"symbol\": \"MSFT\", \"date\": \"2008-10-01T00:00:00\", \"price\": 21.57}, {\"symbol\": \"MSFT\", \"date\": \"2008-11-01T00:00:00\", \"price\": 19.66}, {\"symbol\": \"MSFT\", \"date\": \"2008-12-01T00:00:00\", \"price\": 18.91}, {\"symbol\": \"MSFT\", \"date\": \"2009-01-01T00:00:00\", \"price\": 16.63}, {\"symbol\": \"MSFT\", \"date\": \"2009-02-01T00:00:00\", \"price\": 15.81}, {\"symbol\": \"MSFT\", \"date\": \"2009-03-01T00:00:00\", \"price\": 17.99}, {\"symbol\": \"MSFT\", \"date\": \"2009-04-01T00:00:00\", \"price\": 19.84}, {\"symbol\": \"MSFT\", \"date\": \"2009-05-01T00:00:00\", \"price\": 20.59}, {\"symbol\": \"MSFT\", \"date\": \"2009-06-01T00:00:00\", \"price\": 23.42}, {\"symbol\": \"MSFT\", \"date\": \"2009-07-01T00:00:00\", \"price\": 23.18}, {\"symbol\": \"MSFT\", \"date\": \"2009-08-01T00:00:00\", \"price\": 24.43}, {\"symbol\": \"MSFT\", \"date\": \"2009-09-01T00:00:00\", \"price\": 25.49}, {\"symbol\": \"MSFT\", \"date\": \"2009-10-01T00:00:00\", \"price\": 27.48}, {\"symbol\": \"MSFT\", \"date\": \"2009-11-01T00:00:00\", \"price\": 29.27}, {\"symbol\": \"MSFT\", \"date\": \"2009-12-01T00:00:00\", \"price\": 30.34}, {\"symbol\": \"MSFT\", \"date\": \"2010-01-01T00:00:00\", \"price\": 28.05}, {\"symbol\": \"MSFT\", \"date\": \"2010-02-01T00:00:00\", \"price\": 28.67}, {\"symbol\": \"MSFT\", \"date\": \"2010-03-01T00:00:00\", \"price\": 28.8}, {\"symbol\": \"AMZN\", \"date\": \"2005-02-01T00:00:00\", \"price\": 35.18}, {\"symbol\": \"AMZN\", \"date\": \"2005-03-01T00:00:00\", \"price\": 34.27}, {\"symbol\": \"AMZN\", \"date\": \"2005-04-01T00:00:00\", \"price\": 32.36}, {\"symbol\": \"AMZN\", \"date\": \"2005-05-01T00:00:00\", \"price\": 35.51}, {\"symbol\": \"AMZN\", \"date\": \"2005-06-01T00:00:00\", \"price\": 33.09}, {\"symbol\": \"AMZN\", \"date\": \"2005-07-01T00:00:00\", \"price\": 45.15}, {\"symbol\": \"AMZN\", \"date\": \"2005-08-01T00:00:00\", \"price\": 42.7}, {\"symbol\": \"AMZN\", \"date\": \"2005-09-01T00:00:00\", \"price\": 45.3}, {\"symbol\": \"AMZN\", \"date\": \"2005-10-01T00:00:00\", \"price\": 39.86}, {\"symbol\": \"AMZN\", \"date\": \"2005-11-01T00:00:00\", \"price\": 48.46}, {\"symbol\": \"AMZN\", \"date\": \"2005-12-01T00:00:00\", \"price\": 47.15}, {\"symbol\": \"AMZN\", \"date\": \"2006-01-01T00:00:00\", \"price\": 44.82}, {\"symbol\": \"AMZN\", \"date\": \"2006-02-01T00:00:00\", \"price\": 37.44}, {\"symbol\": \"AMZN\", \"date\": \"2006-03-01T00:00:00\", \"price\": 36.53}, {\"symbol\": \"AMZN\", \"date\": \"2006-04-01T00:00:00\", \"price\": 35.21}, {\"symbol\": \"AMZN\", \"date\": \"2006-05-01T00:00:00\", \"price\": 34.61}, {\"symbol\": \"AMZN\", \"date\": \"2006-06-01T00:00:00\", \"price\": 38.68}, {\"symbol\": \"AMZN\", \"date\": \"2006-07-01T00:00:00\", \"price\": 26.89}, {\"symbol\": \"AMZN\", \"date\": \"2006-08-01T00:00:00\", \"price\": 30.83}, {\"symbol\": \"AMZN\", \"date\": \"2006-09-01T00:00:00\", \"price\": 32.12}, {\"symbol\": \"AMZN\", \"date\": \"2006-10-01T00:00:00\", \"price\": 38.09}, {\"symbol\": \"AMZN\", \"date\": \"2006-11-01T00:00:00\", \"price\": 40.34}, {\"symbol\": \"AMZN\", \"date\": \"2006-12-01T00:00:00\", \"price\": 39.46}, {\"symbol\": \"AMZN\", \"date\": \"2007-01-01T00:00:00\", \"price\": 37.67}, {\"symbol\": \"AMZN\", \"date\": \"2007-02-01T00:00:00\", \"price\": 39.14}, {\"symbol\": \"AMZN\", \"date\": \"2007-03-01T00:00:00\", \"price\": 39.79}, {\"symbol\": \"AMZN\", \"date\": \"2007-04-01T00:00:00\", \"price\": 61.33}, {\"symbol\": \"AMZN\", \"date\": \"2007-05-01T00:00:00\", \"price\": 69.14}, {\"symbol\": \"AMZN\", \"date\": \"2007-06-01T00:00:00\", \"price\": 68.41}, {\"symbol\": \"AMZN\", \"date\": \"2007-07-01T00:00:00\", \"price\": 78.54}, {\"symbol\": \"AMZN\", \"date\": \"2007-08-01T00:00:00\", \"price\": 79.91}, {\"symbol\": \"AMZN\", \"date\": \"2007-09-01T00:00:00\", \"price\": 93.15}, {\"symbol\": \"AMZN\", \"date\": \"2007-10-01T00:00:00\", \"price\": 89.15}, {\"symbol\": \"AMZN\", \"date\": \"2007-11-01T00:00:00\", \"price\": 90.56}, {\"symbol\": \"AMZN\", \"date\": \"2007-12-01T00:00:00\", \"price\": 92.64}, {\"symbol\": \"AMZN\", \"date\": \"2008-01-01T00:00:00\", \"price\": 77.7}, {\"symbol\": \"AMZN\", \"date\": \"2008-02-01T00:00:00\", \"price\": 64.47}, {\"symbol\": \"AMZN\", \"date\": \"2008-03-01T00:00:00\", \"price\": 71.3}, {\"symbol\": \"AMZN\", \"date\": \"2008-04-01T00:00:00\", \"price\": 78.63}, {\"symbol\": \"AMZN\", \"date\": \"2008-05-01T00:00:00\", \"price\": 81.62}, {\"symbol\": \"AMZN\", \"date\": \"2008-06-01T00:00:00\", \"price\": 73.33}, {\"symbol\": \"AMZN\", \"date\": \"2008-07-01T00:00:00\", \"price\": 76.34}, {\"symbol\": \"AMZN\", \"date\": \"2008-08-01T00:00:00\", \"price\": 80.81}, {\"symbol\": \"AMZN\", \"date\": \"2008-09-01T00:00:00\", \"price\": 72.76}, {\"symbol\": \"AMZN\", \"date\": \"2008-10-01T00:00:00\", \"price\": 57.24}, {\"symbol\": \"AMZN\", \"date\": \"2008-11-01T00:00:00\", \"price\": 42.7}, {\"symbol\": \"AMZN\", \"date\": \"2008-12-01T00:00:00\", \"price\": 51.28}, {\"symbol\": \"AMZN\", \"date\": \"2009-01-01T00:00:00\", \"price\": 58.82}, {\"symbol\": \"AMZN\", \"date\": \"2009-02-01T00:00:00\", \"price\": 64.79}, {\"symbol\": \"AMZN\", \"date\": \"2009-03-01T00:00:00\", \"price\": 73.44}, {\"symbol\": \"AMZN\", \"date\": \"2009-04-01T00:00:00\", \"price\": 80.52}, {\"symbol\": \"AMZN\", \"date\": \"2009-05-01T00:00:00\", \"price\": 77.99}, {\"symbol\": \"AMZN\", \"date\": \"2009-06-01T00:00:00\", \"price\": 83.66}, {\"symbol\": \"AMZN\", \"date\": \"2009-07-01T00:00:00\", \"price\": 85.76}, {\"symbol\": \"AMZN\", \"date\": \"2009-08-01T00:00:00\", \"price\": 81.19}, {\"symbol\": \"AMZN\", \"date\": \"2009-09-01T00:00:00\", \"price\": 93.36}, {\"symbol\": \"AMZN\", \"date\": \"2009-10-01T00:00:00\", \"price\": 118.81}, {\"symbol\": \"AMZN\", \"date\": \"2009-11-01T00:00:00\", \"price\": 135.91}, {\"symbol\": \"AMZN\", \"date\": \"2009-12-01T00:00:00\", \"price\": 134.52}, {\"symbol\": \"AMZN\", \"date\": \"2010-01-01T00:00:00\", \"price\": 125.41}, {\"symbol\": \"AMZN\", \"date\": \"2010-02-01T00:00:00\", \"price\": 118.4}, {\"symbol\": \"AMZN\", \"date\": \"2010-03-01T00:00:00\", \"price\": 128.82}, {\"symbol\": \"IBM\", \"date\": \"2005-02-01T00:00:00\", \"price\": 85.78}, {\"symbol\": \"IBM\", \"date\": \"2005-03-01T00:00:00\", \"price\": 84.66}, {\"symbol\": \"IBM\", \"date\": \"2005-04-01T00:00:00\", \"price\": 70.77}, {\"symbol\": \"IBM\", \"date\": \"2005-05-01T00:00:00\", \"price\": 70.18}, {\"symbol\": \"IBM\", \"date\": \"2005-06-01T00:00:00\", \"price\": 68.93}, {\"symbol\": \"IBM\", \"date\": \"2005-07-01T00:00:00\", \"price\": 77.53}, {\"symbol\": \"IBM\", \"date\": \"2005-08-01T00:00:00\", \"price\": 75.07}, {\"symbol\": \"IBM\", \"date\": \"2005-09-01T00:00:00\", \"price\": 74.7}, {\"symbol\": \"IBM\", \"date\": \"2005-10-01T00:00:00\", \"price\": 76.25}, {\"symbol\": \"IBM\", \"date\": \"2005-11-01T00:00:00\", \"price\": 82.98}, {\"symbol\": \"IBM\", \"date\": \"2005-12-01T00:00:00\", \"price\": 76.73}, {\"symbol\": \"IBM\", \"date\": \"2006-01-01T00:00:00\", \"price\": 75.89}, {\"symbol\": \"IBM\", \"date\": \"2006-02-01T00:00:00\", \"price\": 75.09}, {\"symbol\": \"IBM\", \"date\": \"2006-03-01T00:00:00\", \"price\": 77.17}, {\"symbol\": \"IBM\", \"date\": \"2006-04-01T00:00:00\", \"price\": 77.05}, {\"symbol\": \"IBM\", \"date\": \"2006-05-01T00:00:00\", \"price\": 75.04}, {\"symbol\": \"IBM\", \"date\": \"2006-06-01T00:00:00\", \"price\": 72.15}, {\"symbol\": \"IBM\", \"date\": \"2006-07-01T00:00:00\", \"price\": 72.7}, {\"symbol\": \"IBM\", \"date\": \"2006-08-01T00:00:00\", \"price\": 76.35}, {\"symbol\": \"IBM\", \"date\": \"2006-09-01T00:00:00\", \"price\": 77.26}, {\"symbol\": \"IBM\", \"date\": \"2006-10-01T00:00:00\", \"price\": 87.06}, {\"symbol\": \"IBM\", \"date\": \"2006-11-01T00:00:00\", \"price\": 86.95}, {\"symbol\": \"IBM\", \"date\": \"2006-12-01T00:00:00\", \"price\": 91.9}, {\"symbol\": \"IBM\", \"date\": \"2007-01-01T00:00:00\", \"price\": 93.79}, {\"symbol\": \"IBM\", \"date\": \"2007-02-01T00:00:00\", \"price\": 88.18}, {\"symbol\": \"IBM\", \"date\": \"2007-03-01T00:00:00\", \"price\": 89.44}, {\"symbol\": \"IBM\", \"date\": \"2007-04-01T00:00:00\", \"price\": 96.98}, {\"symbol\": \"IBM\", \"date\": \"2007-05-01T00:00:00\", \"price\": 101.54}, {\"symbol\": \"IBM\", \"date\": \"2007-06-01T00:00:00\", \"price\": 100.25}, {\"symbol\": \"IBM\", \"date\": \"2007-07-01T00:00:00\", \"price\": 105.4}, {\"symbol\": \"IBM\", \"date\": \"2007-08-01T00:00:00\", \"price\": 111.54}, {\"symbol\": \"IBM\", \"date\": \"2007-09-01T00:00:00\", \"price\": 112.6}, {\"symbol\": \"IBM\", \"date\": \"2007-10-01T00:00:00\", \"price\": 111.0}, {\"symbol\": \"IBM\", \"date\": \"2007-11-01T00:00:00\", \"price\": 100.9}, {\"symbol\": \"IBM\", \"date\": \"2007-12-01T00:00:00\", \"price\": 103.7}, {\"symbol\": \"IBM\", \"date\": \"2008-01-01T00:00:00\", \"price\": 102.75}, {\"symbol\": \"IBM\", \"date\": \"2008-02-01T00:00:00\", \"price\": 109.64}, {\"symbol\": \"IBM\", \"date\": \"2008-03-01T00:00:00\", \"price\": 110.87}, {\"symbol\": \"IBM\", \"date\": \"2008-04-01T00:00:00\", \"price\": 116.23}, {\"symbol\": \"IBM\", \"date\": \"2008-05-01T00:00:00\", \"price\": 125.14}, {\"symbol\": \"IBM\", \"date\": \"2008-06-01T00:00:00\", \"price\": 114.6}, {\"symbol\": \"IBM\", \"date\": \"2008-07-01T00:00:00\", \"price\": 123.74}, {\"symbol\": \"IBM\", \"date\": \"2008-08-01T00:00:00\", \"price\": 118.16}, {\"symbol\": \"IBM\", \"date\": \"2008-09-01T00:00:00\", \"price\": 113.53}, {\"symbol\": \"IBM\", \"date\": \"2008-10-01T00:00:00\", \"price\": 90.24}, {\"symbol\": \"IBM\", \"date\": \"2008-11-01T00:00:00\", \"price\": 79.65}, {\"symbol\": \"IBM\", \"date\": \"2008-12-01T00:00:00\", \"price\": 82.15}, {\"symbol\": \"IBM\", \"date\": \"2009-01-01T00:00:00\", \"price\": 89.46}, {\"symbol\": \"IBM\", \"date\": \"2009-02-01T00:00:00\", \"price\": 90.32}, {\"symbol\": \"IBM\", \"date\": \"2009-03-01T00:00:00\", \"price\": 95.09}, {\"symbol\": \"IBM\", \"date\": \"2009-04-01T00:00:00\", \"price\": 101.29}, {\"symbol\": \"IBM\", \"date\": \"2009-05-01T00:00:00\", \"price\": 104.85}, {\"symbol\": \"IBM\", \"date\": \"2009-06-01T00:00:00\", \"price\": 103.01}, {\"symbol\": \"IBM\", \"date\": \"2009-07-01T00:00:00\", \"price\": 116.34}, {\"symbol\": \"IBM\", \"date\": \"2009-08-01T00:00:00\", \"price\": 117.0}, {\"symbol\": \"IBM\", \"date\": \"2009-09-01T00:00:00\", \"price\": 118.55}, {\"symbol\": \"IBM\", \"date\": \"2009-10-01T00:00:00\", \"price\": 119.54}, {\"symbol\": \"IBM\", \"date\": \"2009-11-01T00:00:00\", \"price\": 125.79}, {\"symbol\": \"IBM\", \"date\": \"2009-12-01T00:00:00\", \"price\": 130.32}, {\"symbol\": \"IBM\", \"date\": \"2010-01-01T00:00:00\", \"price\": 121.85}, {\"symbol\": \"IBM\", \"date\": \"2010-02-01T00:00:00\", \"price\": 127.16}, {\"symbol\": \"IBM\", \"date\": \"2010-03-01T00:00:00\", \"price\": 125.55}, {\"symbol\": \"GOOG\", \"date\": \"2005-02-01T00:00:00\", \"price\": 187.99}, {\"symbol\": \"GOOG\", \"date\": \"2005-03-01T00:00:00\", \"price\": 180.51}, {\"symbol\": \"GOOG\", \"date\": \"2005-04-01T00:00:00\", \"price\": 220.0}, {\"symbol\": \"GOOG\", \"date\": \"2005-05-01T00:00:00\", \"price\": 277.27}, {\"symbol\": \"GOOG\", \"date\": \"2005-06-01T00:00:00\", \"price\": 294.15}, {\"symbol\": \"GOOG\", \"date\": \"2005-07-01T00:00:00\", \"price\": 287.76}, {\"symbol\": \"GOOG\", \"date\": \"2005-08-01T00:00:00\", \"price\": 286.0}, {\"symbol\": \"GOOG\", \"date\": \"2005-09-01T00:00:00\", \"price\": 316.46}, {\"symbol\": \"GOOG\", \"date\": \"2005-10-01T00:00:00\", \"price\": 372.14}, {\"symbol\": \"GOOG\", \"date\": \"2005-11-01T00:00:00\", \"price\": 404.91}, {\"symbol\": \"GOOG\", \"date\": \"2005-12-01T00:00:00\", \"price\": 414.86}, {\"symbol\": \"GOOG\", \"date\": \"2006-01-01T00:00:00\", \"price\": 432.66}, {\"symbol\": \"GOOG\", \"date\": \"2006-02-01T00:00:00\", \"price\": 362.62}, {\"symbol\": \"GOOG\", \"date\": \"2006-03-01T00:00:00\", \"price\": 390.0}, {\"symbol\": \"GOOG\", \"date\": \"2006-04-01T00:00:00\", \"price\": 417.94}, {\"symbol\": \"GOOG\", \"date\": \"2006-05-01T00:00:00\", \"price\": 371.82}, {\"symbol\": \"GOOG\", \"date\": \"2006-06-01T00:00:00\", \"price\": 419.33}, {\"symbol\": \"GOOG\", \"date\": \"2006-07-01T00:00:00\", \"price\": 386.6}, {\"symbol\": \"GOOG\", \"date\": \"2006-08-01T00:00:00\", \"price\": 378.53}, {\"symbol\": \"GOOG\", \"date\": \"2006-09-01T00:00:00\", \"price\": 401.9}, {\"symbol\": \"GOOG\", \"date\": \"2006-10-01T00:00:00\", \"price\": 476.39}, {\"symbol\": \"GOOG\", \"date\": \"2006-11-01T00:00:00\", \"price\": 484.81}, {\"symbol\": \"GOOG\", \"date\": \"2006-12-01T00:00:00\", \"price\": 460.48}, {\"symbol\": \"GOOG\", \"date\": \"2007-01-01T00:00:00\", \"price\": 501.5}, {\"symbol\": \"GOOG\", \"date\": \"2007-02-01T00:00:00\", \"price\": 449.45}, {\"symbol\": \"GOOG\", \"date\": \"2007-03-01T00:00:00\", \"price\": 458.16}, {\"symbol\": \"GOOG\", \"date\": \"2007-04-01T00:00:00\", \"price\": 471.38}, {\"symbol\": \"GOOG\", \"date\": \"2007-05-01T00:00:00\", \"price\": 497.91}, {\"symbol\": \"GOOG\", \"date\": \"2007-06-01T00:00:00\", \"price\": 522.7}, {\"symbol\": \"GOOG\", \"date\": \"2007-07-01T00:00:00\", \"price\": 510.0}, {\"symbol\": \"GOOG\", \"date\": \"2007-08-01T00:00:00\", \"price\": 515.25}, {\"symbol\": \"GOOG\", \"date\": \"2007-09-01T00:00:00\", \"price\": 567.27}, {\"symbol\": \"GOOG\", \"date\": \"2007-10-01T00:00:00\", \"price\": 707.0}, {\"symbol\": \"GOOG\", \"date\": \"2007-11-01T00:00:00\", \"price\": 693.0}, {\"symbol\": \"GOOG\", \"date\": \"2007-12-01T00:00:00\", \"price\": 691.48}, {\"symbol\": \"GOOG\", \"date\": \"2008-01-01T00:00:00\", \"price\": 564.3}, {\"symbol\": \"GOOG\", \"date\": \"2008-02-01T00:00:00\", \"price\": 471.18}, {\"symbol\": \"GOOG\", \"date\": \"2008-03-01T00:00:00\", \"price\": 440.47}, {\"symbol\": \"GOOG\", \"date\": \"2008-04-01T00:00:00\", \"price\": 574.29}, {\"symbol\": \"GOOG\", \"date\": \"2008-05-01T00:00:00\", \"price\": 585.8}, {\"symbol\": \"GOOG\", \"date\": \"2008-06-01T00:00:00\", \"price\": 526.42}, {\"symbol\": \"GOOG\", \"date\": \"2008-07-01T00:00:00\", \"price\": 473.75}, {\"symbol\": \"GOOG\", \"date\": \"2008-08-01T00:00:00\", \"price\": 463.29}, {\"symbol\": \"GOOG\", \"date\": \"2008-09-01T00:00:00\", \"price\": 400.52}, {\"symbol\": \"GOOG\", \"date\": \"2008-10-01T00:00:00\", \"price\": 359.36}, {\"symbol\": \"GOOG\", \"date\": \"2008-11-01T00:00:00\", \"price\": 292.96}, {\"symbol\": \"GOOG\", \"date\": \"2008-12-01T00:00:00\", \"price\": 307.65}, {\"symbol\": \"GOOG\", \"date\": \"2009-01-01T00:00:00\", \"price\": 338.53}, {\"symbol\": \"GOOG\", \"date\": \"2009-02-01T00:00:00\", \"price\": 337.99}, {\"symbol\": \"GOOG\", \"date\": \"2009-03-01T00:00:00\", \"price\": 348.06}, {\"symbol\": \"GOOG\", \"date\": \"2009-04-01T00:00:00\", \"price\": 395.97}, {\"symbol\": \"GOOG\", \"date\": \"2009-05-01T00:00:00\", \"price\": 417.23}, {\"symbol\": \"GOOG\", \"date\": \"2009-06-01T00:00:00\", \"price\": 421.59}, {\"symbol\": \"GOOG\", \"date\": \"2009-07-01T00:00:00\", \"price\": 443.05}, {\"symbol\": \"GOOG\", \"date\": \"2009-08-01T00:00:00\", \"price\": 461.67}, {\"symbol\": \"GOOG\", \"date\": \"2009-09-01T00:00:00\", \"price\": 495.85}, {\"symbol\": \"GOOG\", \"date\": \"2009-10-01T00:00:00\", \"price\": 536.12}, {\"symbol\": \"GOOG\", \"date\": \"2009-11-01T00:00:00\", \"price\": 583.0}, {\"symbol\": \"GOOG\", \"date\": \"2009-12-01T00:00:00\", \"price\": 619.98}, {\"symbol\": \"GOOG\", \"date\": \"2010-01-01T00:00:00\", \"price\": 529.94}, {\"symbol\": \"GOOG\", \"date\": \"2010-02-01T00:00:00\", \"price\": 526.8}, {\"symbol\": \"GOOG\", \"date\": \"2010-03-01T00:00:00\", \"price\": 560.19}, {\"symbol\": \"AAPL\", \"date\": \"2005-02-01T00:00:00\", \"price\": 44.86}, {\"symbol\": \"AAPL\", \"date\": \"2005-03-01T00:00:00\", \"price\": 41.67}, {\"symbol\": \"AAPL\", \"date\": \"2005-04-01T00:00:00\", \"price\": 36.06}, {\"symbol\": \"AAPL\", \"date\": \"2005-05-01T00:00:00\", \"price\": 39.76}, {\"symbol\": \"AAPL\", \"date\": \"2005-06-01T00:00:00\", \"price\": 36.81}, {\"symbol\": \"AAPL\", \"date\": \"2005-07-01T00:00:00\", \"price\": 42.65}, {\"symbol\": \"AAPL\", \"date\": \"2005-08-01T00:00:00\", \"price\": 46.89}, {\"symbol\": \"AAPL\", \"date\": \"2005-09-01T00:00:00\", \"price\": 53.61}, {\"symbol\": \"AAPL\", \"date\": \"2005-10-01T00:00:00\", \"price\": 57.59}, {\"symbol\": \"AAPL\", \"date\": \"2005-11-01T00:00:00\", \"price\": 67.82}, {\"symbol\": \"AAPL\", \"date\": \"2005-12-01T00:00:00\", \"price\": 71.89}, {\"symbol\": \"AAPL\", \"date\": \"2006-01-01T00:00:00\", \"price\": 75.51}, {\"symbol\": \"AAPL\", \"date\": \"2006-02-01T00:00:00\", \"price\": 68.49}, {\"symbol\": \"AAPL\", \"date\": \"2006-03-01T00:00:00\", \"price\": 62.72}, {\"symbol\": \"AAPL\", \"date\": \"2006-04-01T00:00:00\", \"price\": 70.39}, {\"symbol\": \"AAPL\", \"date\": \"2006-05-01T00:00:00\", \"price\": 59.77}, {\"symbol\": \"AAPL\", \"date\": \"2006-06-01T00:00:00\", \"price\": 57.27}, {\"symbol\": \"AAPL\", \"date\": \"2006-07-01T00:00:00\", \"price\": 67.96}, {\"symbol\": \"AAPL\", \"date\": \"2006-08-01T00:00:00\", \"price\": 67.85}, {\"symbol\": \"AAPL\", \"date\": \"2006-09-01T00:00:00\", \"price\": 76.98}, {\"symbol\": \"AAPL\", \"date\": \"2006-10-01T00:00:00\", \"price\": 81.08}, {\"symbol\": \"AAPL\", \"date\": \"2006-11-01T00:00:00\", \"price\": 91.66}, {\"symbol\": \"AAPL\", \"date\": \"2006-12-01T00:00:00\", \"price\": 84.84}, {\"symbol\": \"AAPL\", \"date\": \"2007-01-01T00:00:00\", \"price\": 85.73}, {\"symbol\": \"AAPL\", \"date\": \"2007-02-01T00:00:00\", \"price\": 84.61}, {\"symbol\": \"AAPL\", \"date\": \"2007-03-01T00:00:00\", \"price\": 92.91}, {\"symbol\": \"AAPL\", \"date\": \"2007-04-01T00:00:00\", \"price\": 99.8}, {\"symbol\": \"AAPL\", \"date\": \"2007-05-01T00:00:00\", \"price\": 121.19}, {\"symbol\": \"AAPL\", \"date\": \"2007-06-01T00:00:00\", \"price\": 122.04}, {\"symbol\": \"AAPL\", \"date\": \"2007-07-01T00:00:00\", \"price\": 131.76}, {\"symbol\": \"AAPL\", \"date\": \"2007-08-01T00:00:00\", \"price\": 138.48}, {\"symbol\": \"AAPL\", \"date\": \"2007-09-01T00:00:00\", \"price\": 153.47}, {\"symbol\": \"AAPL\", \"date\": \"2007-10-01T00:00:00\", \"price\": 189.95}, {\"symbol\": \"AAPL\", \"date\": \"2007-11-01T00:00:00\", \"price\": 182.22}, {\"symbol\": \"AAPL\", \"date\": \"2007-12-01T00:00:00\", \"price\": 198.08}, {\"symbol\": \"AAPL\", \"date\": \"2008-01-01T00:00:00\", \"price\": 135.36}, {\"symbol\": \"AAPL\", \"date\": \"2008-02-01T00:00:00\", \"price\": 125.02}, {\"symbol\": \"AAPL\", \"date\": \"2008-03-01T00:00:00\", \"price\": 143.5}, {\"symbol\": \"AAPL\", \"date\": \"2008-04-01T00:00:00\", \"price\": 173.95}, {\"symbol\": \"AAPL\", \"date\": \"2008-05-01T00:00:00\", \"price\": 188.75}, {\"symbol\": \"AAPL\", \"date\": \"2008-06-01T00:00:00\", \"price\": 167.44}, {\"symbol\": \"AAPL\", \"date\": \"2008-07-01T00:00:00\", \"price\": 158.95}, {\"symbol\": \"AAPL\", \"date\": \"2008-08-01T00:00:00\", \"price\": 169.53}, {\"symbol\": \"AAPL\", \"date\": \"2008-09-01T00:00:00\", \"price\": 113.66}, {\"symbol\": \"AAPL\", \"date\": \"2008-10-01T00:00:00\", \"price\": 107.59}, {\"symbol\": \"AAPL\", \"date\": \"2008-11-01T00:00:00\", \"price\": 92.67}, {\"symbol\": \"AAPL\", \"date\": \"2008-12-01T00:00:00\", \"price\": 85.35}, {\"symbol\": \"AAPL\", \"date\": \"2009-01-01T00:00:00\", \"price\": 90.13}, {\"symbol\": \"AAPL\", \"date\": \"2009-02-01T00:00:00\", \"price\": 89.31}, {\"symbol\": \"AAPL\", \"date\": \"2009-03-01T00:00:00\", \"price\": 105.12}, {\"symbol\": \"AAPL\", \"date\": \"2009-04-01T00:00:00\", \"price\": 125.83}, {\"symbol\": \"AAPL\", \"date\": \"2009-05-01T00:00:00\", \"price\": 135.81}, {\"symbol\": \"AAPL\", \"date\": \"2009-06-01T00:00:00\", \"price\": 142.43}, {\"symbol\": \"AAPL\", \"date\": \"2009-07-01T00:00:00\", \"price\": 163.39}, {\"symbol\": \"AAPL\", \"date\": \"2009-08-01T00:00:00\", \"price\": 168.21}, {\"symbol\": \"AAPL\", \"date\": \"2009-09-01T00:00:00\", \"price\": 185.35}, {\"symbol\": \"AAPL\", \"date\": \"2009-10-01T00:00:00\", \"price\": 188.5}, {\"symbol\": \"AAPL\", \"date\": \"2009-11-01T00:00:00\", \"price\": 199.91}, {\"symbol\": \"AAPL\", \"date\": \"2009-12-01T00:00:00\", \"price\": 210.73}, {\"symbol\": \"AAPL\", \"date\": \"2010-01-01T00:00:00\", \"price\": 192.06}, {\"symbol\": \"AAPL\", \"date\": \"2010-02-01T00:00:00\", \"price\": 204.62}, {\"symbol\": \"AAPL\", \"date\": \"2010-03-01T00:00:00\", \"price\": 223.02}], \"empty\": [{}]}}, {\"mode\": \"vega-lite\"});\n",
|
|
"</script>"
|
|
],
|
|
"text/plain": [
|
|
"alt.LayerChart(...)"
|
|
]
|
|
},
|
|
"execution_count": 43,
|
|
"metadata": {},
|
|
"output_type": "execute_result"
|
|
}
|
|
],
|
|
"source": [
|
|
"import altair as alt\n",
|
|
"from vega_datasets import data\n",
|
|
"\n",
|
|
"source = data.stocks()\n",
|
|
"source = source[source[\"date\"] > \"2005-01-01\"]\n",
|
|
"\n",
|
|
"lines = (\n",
|
|
" alt.Chart(source)\n",
|
|
" .mark_line()\n",
|
|
" .encode(x=\"date\", y=\"price\", color=\"symbol\")\n",
|
|
")\n",
|
|
"\n",
|
|
"xrule = (\n",
|
|
" alt.Chart()\n",
|
|
" .mark_rule(color=\"black\", strokeWidth=1)\n",
|
|
" .encode(x=alt.datum(alt.DateTime(year=2007, month=\"June\")))\n",
|
|
")\n",
|
|
"\n",
|
|
"label = (\n",
|
|
" alt.Chart()\n",
|
|
" .mark_text(color=\"black\", dx=-45, dy=-130)\n",
|
|
" .encode(\n",
|
|
" x=alt.datum(alt.DateTime(year=2007, month=\"June\")),\n",
|
|
" text=alt.datum(\"iPhone Released\"),\n",
|
|
" )\n",
|
|
")\n",
|
|
"\n",
|
|
"xrule2 = (\n",
|
|
" alt.Chart()\n",
|
|
" .mark_text(color=\"black\", dx=45, dy=60)\n",
|
|
" .encode(x=alt.datum(alt.DateTime(year=2008, month=\"November\")),\n",
|
|
" text=alt.datum(\"2008 Financial Crisis\"),\n",
|
|
" )\n",
|
|
"\n",
|
|
")\n",
|
|
"\n",
|
|
"label2 = (\n",
|
|
" alt.Chart()\n",
|
|
" .mark_rect(color=\"#cccccc33\")\n",
|
|
" .encode(\n",
|
|
" x=alt.datum(alt.DateTime(year=2008, month=\"January\")),\n",
|
|
" x2=alt.datum(alt.DateTime(year=2009, month=\"January\")),\n",
|
|
" text=alt.datum(\"2008 Financial Crisis\"),\n",
|
|
" )\n",
|
|
")\n",
|
|
"\n",
|
|
"\n",
|
|
"lines + label + xrule + xrule2 + label2"
|
|
]
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "44096965-f500-4ebf-81c5-c1e8df9d4ea1",
|
|
"metadata": {},
|
|
"outputs": [],
|
|
"source": []
|
|
},
|
|
{
|
|
"cell_type": "code",
|
|
"execution_count": null,
|
|
"id": "f652c1e0-ed86-45cd-b299-4ab662f2437d",
|
|
"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
|
|
}
|