{ "cells": [ { "cell_type": "code", "id": "13e9db2e", "metadata": { "ExecuteTime": { "end_time": "2025-02-03T08:53:42.535565Z", "start_time": "2025-02-03T08:53:31.347791Z" } }, "source": [ "// Fetch latest versions of libraries descriptors\n", "%useLatestDescriptors\n", "// Add kandy library\n", "%use kandy" ], "outputs": [], "execution_count": 1 }, { "cell_type": "code", "id": "90760de9", "metadata": { "ExecuteTime": { "end_time": "2025-02-03T08:53:42.821900Z", "start_time": "2025-02-03T08:53:42.603641Z" } }, "source": [ "val weatherData = mapOf(\n", " \"time\" to listOf(0, 1, 2, 4, 5, 7, 8, 9),\n", " \"temperature\" to listOf(12.0, 14.2, 15.1, 15.9, 17.9, 15.6, 14.2, 24.3),\n", " \"humidity\" to listOf(0.5, 0.32, 0.11, 0.89, 0.68, 0.57, 0.56, 0.5)\n", ") // Combine data into a map" ], "outputs": [], "execution_count": 2 }, { "cell_type": "code", "id": "4caa8a34", "metadata": { "ExecuteTime": { "end_time": "2025-02-03T08:53:44.143198Z", "start_time": "2025-02-03T08:53:42.870192Z" } }, "source": [ "plot(weatherData) { // Begin plotting\n", " x(\"time\") // Set x-axis with time data\n", " y(\"temperature\") { // Set y-axis with temperature data\n", " // Define scale for temperature (y-axis)\n", " scale = continuous(0.0..25.5)\n", " }\n", "\n", " bars { // Add a bar layer\n", " fillColor(\"humidity\") { // Customizing bar colors based on humidity\n", " // Setting the color range\n", " scale = continuous(range = Color.YELLOW..Color.RED)\n", " }\n", " borderLine.width = 0.0 // Define border line width\n", " }\n", "\n", " line {\n", " width = 3.0 // Set line width\n", " color = Color.hex(\"#6e5596\") // Define line color\n", " type = LineType.DOTDASH // Specify line type\n", " }\n", "\n", " layout { // Set plot layout\n", " title = \"Simple plot with kandy-lets-plot\" // Add title\n", " // Add caption\n", " caption = \"See `examples` section for more\\n complicated and interesting examples!\"\n", " size = 700 to 450 // Plot dimension settings\n", " }\n", "}" ], "outputs": [ { "data": { "text/html": [ " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 6\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 7\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 8\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 9\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0\n", " \n", " \n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", " \n", " \n", " \n", " \n", " 10\n", " \n", " \n", " \n", " \n", " \n", " \n", " 15\n", " \n", " \n", " \n", " \n", " \n", " \n", " 20\n", " \n", " \n", " \n", " \n", " \n", " \n", " 25\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " Simple plot with kandy-lets-plot\n", " \n", " \n", " \n", " \n", " temperature\n", " \n", " \n", " \n", " \n", " time\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " humidity\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0.2\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0.4\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0.6\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0.8\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " See `examples` section for more\n", " \n", " \n", " complicated and interesting examples!\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " " ], "application/plot+json": { "output_type": "lets_plot_spec", "output": { "ggtitle": { "text": "Simple plot with kandy-lets-plot" }, "mapping": {}, "data": { "temperature": [ 12.0, 14.2, 15.1, 15.9, 17.9, 15.6, 14.2, 24.3 ], "humidity": [ 0.5, 0.32, 0.11, 0.89, 0.68, 0.57, 0.56, 0.5 ], "time": [ 0.0, 1.0, 2.0, 4.0, 5.0, 7.0, 8.0, 9.0 ] }, "ggsize": { "width": 700.0, "height": 450.0 }, "kind": "plot", "scales": [ { "aesthetic": "x", "limits": [ null, null ] }, { "aesthetic": "y", "limits": [ 0.0, 25.5 ] }, { "aesthetic": "fill", "scale_mapper_kind": "color_gradient", "high": "#ee6666", "low": "#fac858", "limits": [ null, null ] }, { "aesthetic": "x", "limits": [ null, null ] }, { "aesthetic": "y", "limits": [ 0.0, 25.5 ] } ], "layers": [ { "mapping": { "x": "time", "y": "temperature", "fill": "humidity" }, "stat": "identity", "size": 0.0, "sampling": "none", "inherit_aes": false, "position": "dodge", "geom": "bar" }, { "mapping": { "x": "time", "y": "temperature" }, "stat": "identity", "size": 3.0, "color": "#6e5596", "linetype": "dotdash", "sampling": "none", "inherit_aes": false, "position": "identity", "geom": "line" } ], "caption": { "text": "See `examples` section for more\n complicated and interesting examples!" }, "data_meta": { "series_annotations": [ { "type": "int", "column": "time" }, { "type": "float", "column": "temperature" }, { "type": "float", "column": "humidity" } ] } }, "apply_color_scheme": true, "swing_enabled": true } }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 3 }, { "cell_type": "markdown", "source": [ "### Work with DataFrame" ], "metadata": { "collapsed": false }, "id": "c93a81ee41ebeadc" }, { "cell_type": "code", "source": [ "%use dataframe" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2025-02-03T08:53:51.809470Z", "start_time": "2025-02-03T08:53:44.260450Z" } }, "id": "51885a38fe8d9d9d", "outputs": [], "execution_count": 4 }, { "cell_type": "code", "source": [ "val weatherDf = weatherData.toDataFrame()" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2025-02-03T08:53:52.233496Z", "start_time": "2025-02-03T08:53:51.815045Z" } }, "id": "961ed3743abb455d", "outputs": [], "execution_count": 5 }, { "cell_type": "markdown", "source": [ "Use `DataFrame` auto-generated property columns:" ], "metadata": { "collapsed": false }, "id": "2c306813aeb8e279" }, { "cell_type": "code", "source": [ "weatherDf.plot { // Begin plotting\n", " x(time) // Set x-axis with time data\n", " y(temperature) { // Set y-axis with temperature data\n", " // Define scale for temperature (y-axis)\n", " scale = continuous(0.0..25.5)\n", " }\n", "\n", " bars { // Add a bar layer\n", " fillColor(humidity) { // Customizing bar colors based on humidity\n", " // Setting the color range\n", " scale = continuous(range = Color.YELLOW..Color.RED)\n", " }\n", " borderLine.width = 0.0 // Define border line width\n", " }\n", "\n", " line {\n", " width = 3.0 // Set line width\n", " color = Color.hex(\"#6e5596\") // Define line color\n", " type = LineType.DOTDASH // Specify line type\n", " }\n", "\n", " layout { // Set plot layout\n", " title = \"Simple plot with kandy-lets-plot\" // Add title\n", " // Add caption\n", " caption = \"See `examples` section for more\\n complicated and interesting examples!\"\n", " size = 700 to 450 // Plot dimension settings\n", " }\n", "}" ], "metadata": { "collapsed": false, "ExecuteTime": { "end_time": "2025-02-03T08:53:52.551135Z", "start_time": "2025-02-03T08:53:52.238702Z" } }, "id": "6a5d882e80e7ad85", "outputs": [ { "data": { "text/html": [ " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 1\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 2\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 3\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 4\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 6\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 7\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 8\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 9\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0\n", " \n", " \n", " \n", " \n", " \n", " \n", " 5\n", " \n", " \n", " \n", " \n", " \n", " \n", " 10\n", " \n", " \n", " \n", " \n", " \n", " \n", " 15\n", " \n", " \n", " \n", " \n", " \n", " \n", " 20\n", " \n", " \n", " \n", " \n", " \n", " \n", " 25\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " Simple plot with kandy-lets-plot\n", " \n", " \n", " \n", " \n", " temperature\n", " \n", " \n", " \n", " \n", " time\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " humidity\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0.2\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0.4\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0.6\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " 0.8\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " See `examples` section for more\n", " \n", " \n", " complicated and interesting examples!\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "\n", " " ], "application/plot+json": { "output_type": "lets_plot_spec", "output": { "ggtitle": { "text": "Simple plot with kandy-lets-plot" }, "mapping": {}, "data": { "temperature": [ 12.0, 14.2, 15.1, 15.9, 17.9, 15.6, 14.2, 24.3 ], "humidity": [ 0.5, 0.32, 0.11, 0.89, 0.68, 0.57, 0.56, 0.5 ], "time": [ 0.0, 1.0, 2.0, 4.0, 5.0, 7.0, 8.0, 9.0 ] }, "ggsize": { "width": 700.0, "height": 450.0 }, "kind": "plot", "scales": [ { "aesthetic": "x", "limits": [ null, null ] }, { "aesthetic": "y", "limits": [ 0.0, 25.5 ] }, { "aesthetic": "fill", "scale_mapper_kind": "color_gradient", "high": "#ee6666", "low": "#fac858", "limits": [ null, null ] }, { "aesthetic": "x", "limits": [ null, null ] }, { "aesthetic": "y", "limits": [ 0.0, 25.5 ] } ], "layers": [ { "mapping": { "x": "time", "y": "temperature", "fill": "humidity" }, "stat": "identity", "size": 0.0, "sampling": "none", "inherit_aes": false, "position": "dodge", "geom": "bar" }, { "mapping": { "x": "time", "y": "temperature" }, "stat": "identity", "size": 3.0, "color": "#6e5596", "linetype": "dotdash", "sampling": "none", "inherit_aes": false, "position": "identity", "geom": "line" } ], "caption": { "text": "See `examples` section for more\n complicated and interesting examples!" }, "data_meta": { "series_annotations": [ { "type": "int", "column": "time" }, { "type": "float", "column": "temperature" }, { "type": "float", "column": "humidity" } ] } }, "apply_color_scheme": true, "swing_enabled": true } }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "execution_count": 6 } ], "metadata": { "kernelspec": { "display_name": "Kotlin", "language": "kotlin", "name": "kotlin" }, "language_info": { "codemirror_mode": "text/x-kotlin", "file_extension": ".kt", "mimetype": "text/x-kotlin", "name": "kotlin", "nbconvert_exporter": "", "pygments_lexer": "kotlin", "version": "1.8.20-Beta" }, "ktnbPluginMetadata": { "projectLibraries": [] } }, "nbformat": 4, "nbformat_minor": 5 }