{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "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/\n" ] }, { "cell_type": "code", "execution_count": 1, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "import pandas as pd\n", "from lets_plot import *\n", "\n", "LetsPlot.setup_html()" ] }, { "cell_type": "code", "execution_count": 2, "metadata": {}, "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": 2, "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": 3, "metadata": {}, "outputs": [], "source": [ "def pair(p0, p1):\n", " bunch = GGBunch()\n", " bunch.add_plot(p0, x=0, y=0, width=500, height=300)\n", " bunch.add_plot(p1, x=500, y=0, width=500, height=300)\n", " return bunch" ] }, { "cell_type": "code", "execution_count": 4, "metadata": {}, "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": 5, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 5, "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": 6, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 6, "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": 7, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 7, "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\"\n" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "#### Magma" ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 8, "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": 9, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 9, "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": 10, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 10, "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": 11, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 11, "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": 12, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 12, "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": 13, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 13, "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": 14, "metadata": {}, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 14, "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.7.13" } }, "nbformat": 4, "nbformat_minor": 4 }