{ "cells": [ { "cell_type": "markdown", "id": "social-orange", "metadata": {}, "source": [ "The `viridis` color maps are designed to be perceptually-uniform, both in regular form and also when converted to black-and-white.\n", "\n", "More info: https://bids.github.io/colormap/" ] }, { "cell_type": "code", "execution_count": 1, "id": "unknown-parker", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "%useLatestDescriptors\n", "%use lets-plot\n", "%use dataframe" ] }, { "cell_type": "code", "execution_count": 2, "id": "committed-longitude", "metadata": {}, "outputs": [ { "data": { "text/plain": [ "Lets-Plot Kotlin API v.4.4.2. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.0.0." ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "LetsPlot.getInfo()" ] }, { "cell_type": "code", "execution_count": 3, "id": "reliable-rates", "metadata": {}, "outputs": [ { "data": { "application/kotlindataframe+json": "{\"nrow\":3,\"ncol\":9,\"columns\":[\"miles per gallon\",\"number of cylinders\",\"engine displacement (cu. inches)\",\"engine horsepower\",\"vehicle weight (lbs.)\",\"time to accelerate (sec.)\",\"model year\",\"origin of car\",\"vehicle name\"],\"kotlin_dataframe\":[{\"miles per gallon\":18.0,\"number of cylinders\":8,\"engine displacement (cu. inches)\":307.0,\"engine horsepower\":130,\"vehicle weight (lbs.)\":3504,\"time to accelerate (sec.)\":12.0,\"model year\":70,\"origin of car\":\"US\",\"vehicle name\":\"chevrolet chevelle malibu\"},{\"miles per gallon\":15.0,\"number of cylinders\":8,\"engine displacement (cu. inches)\":350.0,\"engine horsepower\":165,\"vehicle weight (lbs.)\":3693,\"time to accelerate (sec.)\":11.5,\"model year\":70,\"origin of car\":\"US\",\"vehicle name\":\"buick skylark 320\"},{\"miles per gallon\":18.0,\"number of cylinders\":8,\"engine displacement (cu. inches)\":318.0,\"engine horsepower\":150,\"vehicle weight (lbs.)\":3436,\"time to accelerate (sec.)\":11.0,\"model year\":70,\"origin of car\":\"US\",\"vehicle name\":\"plymouth satellite\"}]}", "text/html": [ " \n", " \n", " \n", " \n", " \n", " \n", "
\n", "\n", "

DataFrame: rowsCount = 3, columnsCount = 9

\n", " \n", " \n", " " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "val mpg = DataFrame.readCSV(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg2.csv\")\n", "mpg.head(3)" ] }, { "cell_type": "code", "execution_count": 4, "id": "affected-testament", "metadata": {}, "outputs": [], "source": [ "import org.jetbrains.letsPlot.intern.Plot\n", "\n", "fun pair(p0:Plot, p1:Plot):Figure {\n", " return gggrid(\n", " listOf(p0, p1),\n", " ncol = 2,\n", " cellWidth = 500,\n", " cellHeight = 300,\n", " vGap = 0,\n", " fit = true\n", " )\n", "}" ] }, { "cell_type": "code", "execution_count": 5, "id": "numeric-silver", "metadata": {}, "outputs": [], "source": [ "val pC = letsPlot(mpg.toMap()) + \n", " geomPoint(size = 7) {x = \"vehicle weight (lbs.)\"; y = \"miles per gallon\"; color = \"miles per gallon\"} + \n", " ggtitle(\"Continuous data\") + labs(color = \"MPG\")\n", "\n", "val pD = letsPlot(mpg.toMap()) + geomBar{x = \"origin of car\"; fill = \"origin of car\"} +\n", " ggtitle(\"Discrete data\") + labs(fill = \"\")" ] }, { "cell_type": "markdown", "id": "pretty-cemetery", "metadata": {}, "source": [ "### The \"viridis\" colormap is the default option.\n", "\n", "Adjust scales with `begin, end, alpha` and `direction` parameters." ] }, { "cell_type": "code", "execution_count": 6, "id": "cathedral-shark", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(pC + scaleColorViridis(),\n", " pC + scaleColorViridis(end = 0.5))" ] }, { "cell_type": "code", "execution_count": 7, "id": "mineral-albert", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(pD + scaleFillViridis(),\n", " pD + scaleFillViridis(begin = 0.3, end = 0.8))" ] }, { "cell_type": "code", "execution_count": 8, "id": "looking-sample", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(pD + scaleFillViridis(alpha = 0.4),\n", " pD + scaleFillViridis(begin = 0.3, end = 0.8, direction = -1))" ] }, { "cell_type": "markdown", "id": "expensive-hearts", "metadata": {}, "source": [ "### Supported colormaps\n", "Use the `option` parameter to select a colormap you like:\n", "\n", "- \"magma\" (or \"A\"),\n", "- \"inferno\" (or \"B\")\n", "- \"plasma\" (or \"C\")\n", "- \"viridis\" (or \"D\") - the default\n", "- \"cividis\" (or \"E\")\n", "- \"turbo\"\n", "- \"twilight\"" ] }, { "cell_type": "markdown", "id": "nervous-zealand", "metadata": {}, "source": [ "#### Magma" ] }, { "cell_type": "code", "execution_count": 9, "id": "adjustable-business", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(pC + scaleColorViridis(option = \"A\"),\n", " pD + scaleFillViridis(option = \"magma\"))" ] }, { "cell_type": "markdown", "id": "broken-tsunami", "metadata": {}, "source": [ "#### Inferno" ] }, { "cell_type": "code", "execution_count": 10, "id": "consistent-champion", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(pC + scaleColorViridis(option = \"B\"),\n", " pD + scaleFillViridis(option = \"inferno\"))" ] }, { "cell_type": "markdown", "id": "explicit-cabinet", "metadata": {}, "source": [ "#### Plasma" ] }, { "cell_type": "code", "execution_count": 11, "id": "painted-retailer", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(pC + scaleColorViridis(option = \"C\"),\n", " pD + scaleFillViridis(option = \"plasma\"))" ] }, { "cell_type": "markdown", "id": "quick-reviewer", "metadata": {}, "source": [ "#### Viridis" ] }, { "cell_type": "code", "execution_count": 12, "id": "curious-hearts", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(pC + scaleColorViridis(option = \"D\"),\n", " pD + scaleFillViridis(option = \"viridis\"))" ] }, { "cell_type": "markdown", "id": "cathedral-recipe", "metadata": {}, "source": [ "#### Cividis" ] }, { "cell_type": "code", "execution_count": 13, "id": "german-ownership", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(pC + scaleColorViridis(option = \"E\"),\n", " pD + scaleFillViridis(option = \"cividis\"))" ] }, { "cell_type": "markdown", "id": "indoor-iraqi", "metadata": {}, "source": [ "#### Turbo" ] }, { "cell_type": "code", "execution_count": 14, "id": "pointed-criminal", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(pC + scaleColorViridis(option = \"turbo\", direction = -1),\n", " pD + scaleFillViridis(option = \"turbo\"))" ] }, { "cell_type": "markdown", "id": "likely-notice", "metadata": {}, "source": [ "#### Twilight" ] }, { "cell_type": "code", "execution_count": 15, "id": "prospective-generation", "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(pC + scaleColorViridis(option = \"twilight\"),\n", " pD + scaleFillViridis(option = \"twilight\"))" ] } ], "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" } }, "nbformat": 4, "nbformat_minor": 5 }