{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Colors Viridis\n", "\n", "The `viridis` color maps are designed to be perceptually-uniform,\n", "both in regular form and also when converted to black-and-white.\n", "\n", "More info: [https://bids.github.io/colormap/](https://bids.github.io/colormap/)" ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:08:07.889706Z", "iopub.status.busy": "2026-01-27T17:08:07.889619Z", "iopub.status.idle": "2026-01-27T17:08:07.892484Z", "shell.execute_reply": "2026-01-27T17:08:07.892202Z" } }, "outputs": [], "source": [ "import pandas as pd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:08:07.893353Z", "iopub.status.busy": "2026-01-27T17:08:07.893280Z", "iopub.status.idle": "2026-01-27T17:08:07.894809Z", "shell.execute_reply": "2026-01-27T17:08:07.894615Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:08:07.908064Z", "iopub.status.busy": "2026-01-27T17:08:07.907990Z", "iopub.status.idle": "2026-01-27T17:08:08.019711Z", "shell.execute_reply": "2026-01-27T17:08:08.019276Z" } }, "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", "
miles per gallonnumber of cylindersengine displacement (cu. inches)engine horsepowervehicle weight (lbs.)time to accelerate (sec.)model yearorigin of carvehicle name
018.08307.0130350412.070USchevrolet chevelle malibu
115.08350.0165369311.570USbuick skylark 320
218.08318.0150343611.070USplymouth satellite
\n", "
" ], "text/plain": [ " miles per gallon number of cylinders engine displacement (cu. inches) \\\n", "0 18.0 8 307.0 \n", "1 15.0 8 350.0 \n", "2 18.0 8 318.0 \n", "\n", " engine horsepower vehicle weight (lbs.) time to accelerate (sec.) \\\n", "0 130 3504 12.0 \n", "1 165 3693 11.5 \n", "2 150 3436 11.0 \n", "\n", " model year origin of car vehicle name \n", "0 70 US chevrolet chevelle malibu \n", "1 70 US buick skylark 320 \n", "2 70 US plymouth satellite " ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mpg = pd.read_csv (\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/data/mpg2.csv\")\n", "mpg.head(3)" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:08:08.020788Z", "iopub.status.busy": "2026-01-27T17:08:08.020712Z", "iopub.status.idle": "2026-01-27T17:08:08.022100Z", "shell.execute_reply": "2026-01-27T17:08:08.021890Z" } }, "outputs": [], "source": [ "def pair(p0, p1):\n", " return gggrid([p0, p1]) + ggsize(1000, 300)" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:08:08.023048Z", "iopub.status.busy": "2026-01-27T17:08:08.022979Z", "iopub.status.idle": "2026-01-27T17:08:08.047107Z", "shell.execute_reply": "2026-01-27T17:08:08.046864Z" } }, "outputs": [], "source": [ "p_c = (ggplot(mpg) + \n", " geom_point(aes(\"vehicle weight (lbs.)\", \"miles per gallon\", color=\"miles per gallon\"), size=7) + \n", " ggtitle(\"Continuous data\") + labs(color=\"MPG\"))\n", "\n", "p_d = (ggplot(mpg) + geom_bar(aes(\"origin of car\", fill=\"origin of car\")) +\n", " ggtitle(\"Discrete data\") + labs(fill=\"\"))\n" ] }, { "cell_type": "markdown", "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, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:08:08.048405Z", "iopub.status.busy": "2026-01-27T17:08:08.048293Z", "iopub.status.idle": "2026-01-27T17:08:08.059886Z", "shell.execute_reply": "2026-01-27T17:08:08.059666Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(p_c + scale_color_viridis(),\n", " p_c + scale_color_viridis(end=0.5))" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:08:08.060937Z", "iopub.status.busy": "2026-01-27T17:08:08.060854Z", "iopub.status.idle": "2026-01-27T17:08:08.069204Z", "shell.execute_reply": "2026-01-27T17:08:08.068991Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(p_d + scale_fill_viridis(),\n", " p_d + scale_fill_viridis(begin=0.3, end=0.8))" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:08:08.070293Z", "iopub.status.busy": "2026-01-27T17:08:08.070223Z", "iopub.status.idle": "2026-01-27T17:08:08.078735Z", "shell.execute_reply": "2026-01-27T17:08:08.078519Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(p_d + scale_fill_viridis(alpha=0.4),\n", " p_d + scale_fill_viridis(begin=0.3, end=0.8, direction=-1))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Supported colormaps\n", "\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", "metadata": {}, "source": [ "##### Magma" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:08:08.079870Z", "iopub.status.busy": "2026-01-27T17:08:08.079800Z", "iopub.status.idle": "2026-01-27T17:08:08.087436Z", "shell.execute_reply": "2026-01-27T17:08:08.087249Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(p_c + scale_color_viridis(option=\"A\"),\n", " p_d + scale_fill_viridis(option=\"magma\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Inferno" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:08:08.088584Z", "iopub.status.busy": "2026-01-27T17:08:08.088515Z", "iopub.status.idle": "2026-01-27T17:08:08.095905Z", "shell.execute_reply": "2026-01-27T17:08:08.095702Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(p_c + scale_color_viridis(option=\"B\"),\n", " p_d + scale_fill_viridis(option=\"inferno\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Plasma" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:08:08.097067Z", "iopub.status.busy": "2026-01-27T17:08:08.096996Z", "iopub.status.idle": "2026-01-27T17:08:08.104882Z", "shell.execute_reply": "2026-01-27T17:08:08.104664Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(p_c + scale_color_viridis(option=\"C\"),\n", " p_d + scale_fill_viridis(option=\"plasma\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Viridis" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:08:08.105903Z", "iopub.status.busy": "2026-01-27T17:08:08.105834Z", "iopub.status.idle": "2026-01-27T17:08:08.113616Z", "shell.execute_reply": "2026-01-27T17:08:08.113415Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 12, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(p_c + scale_color_viridis(option=\"D\"),\n", " p_d + scale_fill_viridis(option=\"viridis\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Cividis" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:08:08.114745Z", "iopub.status.busy": "2026-01-27T17:08:08.114675Z", "iopub.status.idle": "2026-01-27T17:08:08.122059Z", "shell.execute_reply": "2026-01-27T17:08:08.121855Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(p_c + scale_color_viridis(option=\"E\"),\n", " p_d + scale_fill_viridis(option=\"cividis\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Turbo" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:08:08.123136Z", "iopub.status.busy": "2026-01-27T17:08:08.123064Z", "iopub.status.idle": "2026-01-27T17:08:08.130593Z", "shell.execute_reply": "2026-01-27T17:08:08.130392Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(p_c + scale_color_viridis(option=\"turbo\", direction=-1),\n", " p_d + scale_fill_viridis(option=\"turbo\"))" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "##### Twilight" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "execution": { "iopub.execute_input": "2026-01-27T17:08:08.131525Z", "iopub.status.busy": "2026-01-27T17:08:08.131457Z", "iopub.status.idle": "2026-01-27T17:08:08.139200Z", "shell.execute_reply": "2026-01-27T17:08:08.138975Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pair(p_c + scale_color_viridis(option=\"twilight\"),\n", " p_d + scale_fill_viridis(option=\"twilight\"))" ] } ], "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.13" } }, "nbformat": 4, "nbformat_minor": 4 }