Last active
May 3, 2018 04:51
-
-
Save xerial/ddaaa8d53c4515c8a3cd4239f2c8e691 to your computer and use it in GitHub Desktop.
Scala Jupyter Notebook Plot Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
"cells": [ | |
{ | |
"cell_type": "code", | |
"execution_count": 4, | |
"metadata": { | |
"scrolled": false | |
}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/plain": [ | |
"\u001b[32mimport \u001b[39m\u001b[36m$ivy.$ \n", | |
"\u001b[39m\n", | |
"\u001b[32mimport \u001b[39m\u001b[36mvegas._\u001b[39m" | |
] | |
}, | |
"execution_count": 4, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"import $ivy.`org.vegas-viz::vegas:0.3.11`\n", | |
"import vegas._" | |
] | |
}, | |
{ | |
"cell_type": "code", | |
"execution_count": 3, | |
"metadata": {}, | |
"outputs": [ | |
{ | |
"data": { | |
"text/html": [ | |
"\n", | |
" <iframe id=\"frame-vegas-e6551ad3-d0b4-4d51-aa93-ebc7e5e9c3a9\" sandbox=\"allow-scripts allow-same-origin\" style=\"border: none; width: 100%\" srcdoc=\"<html>\n", | |
" <head>\n", | |
" <script src="https://cdn.jsdelivr.net/webjars/org.webjars.bower/d3/3.5.17/d3.min.js" charset="utf-8"></script>\n", | |
"<script src="https://cdn.jsdelivr.net/webjars/org.webjars.bower/vega/2.6.3/vega.min.js" charset="utf-8"></script>\n", | |
"<script src="https://cdn.jsdelivr.net/webjars/org.webjars.bower/vega-lite/1.2.0/vega-lite.min.js" charset="utf-8"></script>\n", | |
"<script src="https://vega.github.io/vega-editor/vendor/vega-embed.js" charset="utf-8"></script>\n", | |
" </head>\n", | |
" <body>\n", | |
" <div id='vegas-e6551ad3-d0b4-4d51-aa93-ebc7e5e9c3a9'></div>\n", | |
" <script>\n", | |
" var embedSpec = {\n", | |
" mode: "vega-lite",\n", | |
" spec: {\n", | |
" "mark" : "bar",\n", | |
" "encoding" : {\n", | |
" "x" : {\n", | |
" "field" : "country",\n", | |
" "type" : "nominal"\n", | |
" },\n", | |
" "y" : {\n", | |
" "field" : "population",\n", | |
" "type" : "quantitative"\n", | |
" }\n", | |
" },\n", | |
" "description" : "Country Pop",\n", | |
" "data" : {\n", | |
" "values" : [\n", | |
" {\n", | |
" "country" : "USA",\n", | |
" "population" : 314\n", | |
" },\n", | |
" {\n", | |
" "country" : "UK",\n", | |
" "population" : 64\n", | |
" },\n", | |
" {\n", | |
" "country" : "DK",\n", | |
" "population" : 80\n", | |
" }\n", | |
" ]\n", | |
" }\n", | |
"}\n", | |
" }\n", | |
" vg.embed("#vegas-e6551ad3-d0b4-4d51-aa93-ebc7e5e9c3a9", embedSpec, function(error, result) {});\n", | |
" </script>\n", | |
"\n", | |
" </body>\n", | |
"</html>\"></iframe>\n", | |
" <script>\n", | |
" (function() {\n", | |
" function resizeIFrame(el, k) {\n", | |
" var height = el.contentWindow.document.body.scrollHeight || '400'; // Fallback in case of no scroll height\n", | |
" el.style.height = height + 'px';\n", | |
" if (k <= 10) { setTimeout(function() { resizeIFrame(el, k+1) }, 1000 + (k * 250)) };\n", | |
" }\n", | |
" resizeIFrame(document.querySelector('#frame-vegas-e6551ad3-d0b4-4d51-aa93-ebc7e5e9c3a9'), 1);\n", | |
" })(); // IIFE\n", | |
" </script>\n", | |
" " | |
] | |
}, | |
"metadata": {}, | |
"output_type": "display_data" | |
}, | |
{ | |
"data": { | |
"text/plain": [ | |
"\u001b[32mimport \u001b[39m\u001b[36mvegas._\n", | |
"\n", | |
"\u001b[39m" | |
] | |
}, | |
"execution_count": 3, | |
"metadata": {}, | |
"output_type": "execute_result" | |
} | |
], | |
"source": [ | |
"import vegas._\n", | |
"\n", | |
"Vegas(\"Country Pop\").\n", | |
" withData(\n", | |
" Seq(\n", | |
" Map(\"country\" -> \"USA\", \"population\" -> 314),\n", | |
" Map(\"country\" -> \"UK\", \"population\" -> 64),\n", | |
" Map(\"country\" -> \"DK\", \"population\" -> 80)\n", | |
" )\n", | |
" ).\n", | |
" encodeX(\"country\", Nom).\n", | |
" encodeY(\"population\", Quant).\n", | |
" mark(Bar).\n", | |
" show" | |
] | |
} | |
], | |
"metadata": { | |
"kernelspec": { | |
"display_name": "Scala", | |
"language": "scala", | |
"name": "scala" | |
}, | |
"language_info": { | |
"codemirror_mode": "text/x-scala", | |
"file_extension": ".scala", | |
"mimetype": "text/x-scala", | |
"name": "scala211", | |
"nbconvert_exporter": "script", | |
"pygments_lexer": "scala", | |
"version": "2.11.11" | |
} | |
}, | |
"nbformat": 4, | |
"nbformat_minor": 2 | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment