{ "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": { "execution": { "iopub.execute_input": "2024-08-23T11:00:11.543675Z", "iopub.status.busy": "2024-08-23T11:00:11.542542Z", "iopub.status.idle": "2024-08-23T11:00:14.118628Z", "shell.execute_reply": "2024-08-23T11:00:14.118351Z" } }, "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": { "execution": { "iopub.execute_input": "2024-08-23T11:00:14.120795Z", "iopub.status.busy": "2024-08-23T11:00:14.120546Z", "iopub.status.idle": "2024-08-23T11:00:14.165506Z", "shell.execute_reply": "2024-08-23T11:00:14.165255Z" } }, "outputs": [ { "data": { "text/plain": [ "Lets-Plot Kotlin API v.4.7.2. Frontend: Notebook with dynamically loaded JS. Lets-Plot JS v.4.3.2." ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "LetsPlot.getInfo()" ] }, { "cell_type": "code", "execution_count": 3, "id": "reliable-rates", "metadata": { "execution": { "iopub.execute_input": "2024-08-23T11:00:14.167197Z", "iopub.status.busy": "2024-08-23T11:00:14.166947Z", "iopub.status.idle": "2024-08-23T11:00:14.822668Z", "shell.execute_reply": "2024-08-23T11:00:14.822843Z" } }, "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", "

DataFrame: rowsCount = 3, columnsCount = 9

\n", "
miles per gallonnumber of cylindersengine displacement (cu. inches)engine horsepowervehicle weight (lbs.)time to accelerate (sec.)model yearorigin of carvehicle name
18.0000008307.000000130350412.00000070USchevrolet chevelle malibu
15.0000008350.000000165369311.50000070USbuick skylark 320
18.0000008318.000000150343611.00000070USplymouth satellite
\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": { "execution": { "iopub.execute_input": "2024-08-23T11:00:14.824474Z", "iopub.status.busy": "2024-08-23T11:00:14.824223Z", "iopub.status.idle": "2024-08-23T11:00:14.872014Z", "shell.execute_reply": "2024-08-23T11:00:14.871745Z" } }, "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": { "execution": { "iopub.execute_input": "2024-08-23T11:00:14.874129Z", "iopub.status.busy": "2024-08-23T11:00:14.873818Z", "iopub.status.idle": "2024-08-23T11:00:14.961479Z", "shell.execute_reply": "2024-08-23T11:00:14.961299Z" } }, "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": { "execution": { "iopub.execute_input": "2024-08-23T11:00:14.963394Z", "iopub.status.busy": "2024-08-23T11:00:14.963141Z", "iopub.status.idle": "2024-08-23T11:00:15.067386Z", "shell.execute_reply": "2024-08-23T11:00:15.067497Z" } }, "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": { "execution": { "iopub.execute_input": "2024-08-23T11:00:15.068860Z", "iopub.status.busy": "2024-08-23T11:00:15.068708Z", "iopub.status.idle": "2024-08-23T11:00:15.124985Z", "shell.execute_reply": "2024-08-23T11:00:15.124825Z" } }, "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": { "execution": { "iopub.execute_input": "2024-08-23T11:00:15.126567Z", "iopub.status.busy": "2024-08-23T11:00:15.126414Z", "iopub.status.idle": "2024-08-23T11:00:15.179640Z", "shell.execute_reply": "2024-08-23T11:00:15.179740Z" } }, "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": { "execution": { "iopub.execute_input": "2024-08-23T11:00:15.181270Z", "iopub.status.busy": "2024-08-23T11:00:15.181020Z", "iopub.status.idle": "2024-08-23T11:00:15.229709Z", "shell.execute_reply": "2024-08-23T11:00:15.229501Z" } }, "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": { "execution": { "iopub.execute_input": "2024-08-23T11:00:15.231689Z", "iopub.status.busy": "2024-08-23T11:00:15.231428Z", "iopub.status.idle": "2024-08-23T11:00:15.280830Z", "shell.execute_reply": "2024-08-23T11:00:15.281001Z" } }, "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": { "execution": { "iopub.execute_input": "2024-08-23T11:00:15.282799Z", "iopub.status.busy": "2024-08-23T11:00:15.282556Z", "iopub.status.idle": "2024-08-23T11:00:15.335705Z", "shell.execute_reply": "2024-08-23T11:00:15.335559Z" } }, "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": { "execution": { "iopub.execute_input": "2024-08-23T11:00:15.336840Z", "iopub.status.busy": "2024-08-23T11:00:15.336704Z", "iopub.status.idle": "2024-08-23T11:00:15.386959Z", "shell.execute_reply": "2024-08-23T11:00:15.386743Z" } }, "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": { "execution": { "iopub.execute_input": "2024-08-23T11:00:15.388852Z", "iopub.status.busy": "2024-08-23T11:00:15.388590Z", "iopub.status.idle": "2024-08-23T11:00:15.435499Z", "shell.execute_reply": "2024-08-23T11:00:15.435618Z" } }, "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": { "execution": { "iopub.execute_input": "2024-08-23T11:00:15.437504Z", "iopub.status.busy": "2024-08-23T11:00:15.437247Z", "iopub.status.idle": "2024-08-23T11:00:15.486064Z", "shell.execute_reply": "2024-08-23T11:00:15.485834Z" } }, "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": { "execution": { "iopub.execute_input": "2024-08-23T11:00:15.487996Z", "iopub.status.busy": "2024-08-23T11:00:15.487730Z", "iopub.status.idle": "2024-08-23T11:00:15.535175Z", "shell.execute_reply": "2024-08-23T11:00:15.535351Z" } }, "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.9.23" } }, "nbformat": 4, "nbformat_minor": 5 }