diff --git a/workshops/WS2_colormaps.ipynb b/workshops/WS2_colormaps.ipynb index 41cfc7f..2a54ec4 100644 --- a/workshops/WS2_colormaps.ipynb +++ b/workshops/WS2_colormaps.ipynb @@ -2,7 +2,6 @@ "cells": [ { "cell_type": "markdown", - "id": "8ad0822b", "metadata": {}, "source": [ "# Welcome to the SciViz Workshops\n", @@ -18,19 +17,17 @@ { "cell_type": "code", "execution_count": null, - "id": "b9f7889e", "metadata": {}, "outputs": [], "source": [ "# notebook metadata you can ignore!\n", "info = {\"workshop\": \"02\",\n", " \"topic\": [\"colors\", \"colormaps\", \"normalisation\"],\n", - " \"version\" : \"0.0.1\"}" + " \"version\" : \"0.0.2\"}" ] }, { "cell_type": "markdown", - "id": "6a4cad29", "metadata": {}, "source": [ "### How to use this notebook\n", @@ -45,7 +42,6 @@ }, { "cell_type": "markdown", - "id": "4385d531", "metadata": {}, "source": [ "# What is in this Workshop?\n", @@ -59,7 +55,6 @@ { "cell_type": "code", "execution_count": null, - "id": "490ea1fe", "metadata": {}, "outputs": [], "source": [ @@ -76,7 +71,6 @@ }, { "cell_type": "markdown", - "id": "de61ab7c", "metadata": {}, "source": [ "# Section 1: Preparing Dummy Data" @@ -85,7 +79,6 @@ { "cell_type": "code", "execution_count": null, - "id": "10635f3d", "metadata": {}, "outputs": [], "source": [ @@ -98,7 +91,6 @@ { "cell_type": "code", "execution_count": null, - "id": "2d6a3701", "metadata": {}, "outputs": [], "source": [ @@ -112,7 +104,6 @@ { "cell_type": "code", "execution_count": null, - "id": "557ad5a0", "metadata": {}, "outputs": [], "source": [ @@ -125,7 +116,6 @@ { "cell_type": "code", "execution_count": null, - "id": "63ec1958", "metadata": { "pycharm": { "name": "#%%\n" @@ -139,7 +129,6 @@ { "cell_type": "code", "execution_count": null, - "id": "1a980041", "metadata": { "pycharm": { "name": "#%%\n" @@ -158,7 +147,6 @@ }, { "cell_type": "markdown", - "id": "bf1e794d", "metadata": {}, "source": [ "# Section 2: Colormaps in Matplotlib\n", @@ -175,7 +163,6 @@ { "cell_type": "code", "execution_count": null, - "id": "a0146b93", "metadata": { "pycharm": { "name": "#%%\n" @@ -194,7 +181,6 @@ }, { "cell_type": "markdown", - "id": "e5e24691", "metadata": { "pycharm": { "name": "#%% md\n" @@ -207,7 +193,6 @@ { "cell_type": "code", "execution_count": null, - "id": "d8ab4ac2", "metadata": {}, "outputs": [], "source": [ @@ -219,7 +204,6 @@ }, { "cell_type": "markdown", - "id": "83577fd4", "metadata": {}, "source": [ "And of course, reversed versions of if" @@ -228,7 +212,6 @@ { "cell_type": "code", "execution_count": null, - "id": "8af79b87", "metadata": { "pycharm": { "name": "#%%\n" @@ -242,7 +225,6 @@ }, { "cell_type": "markdown", - "id": "577e7850", "metadata": { "pycharm": { "name": "#%% md\n" @@ -255,7 +237,6 @@ { "cell_type": "code", "execution_count": null, - "id": "e4fe46b5", "metadata": { "pycharm": { "name": "#%%\n" @@ -270,7 +251,6 @@ }, { "cell_type": "markdown", - "id": "20a08fa7", "metadata": {}, "source": [ "### Diverging" @@ -279,7 +259,6 @@ { "cell_type": "code", "execution_count": null, - "id": "b66fefc9", "metadata": { "pycharm": { "name": "#%%\n" @@ -294,7 +273,6 @@ }, { "cell_type": "markdown", - "id": "4d317def", "metadata": {}, "source": [ "### Cycling" @@ -303,7 +281,6 @@ { "cell_type": "code", "execution_count": null, - "id": "04f32d2b", "metadata": { "pycharm": { "name": "#%%\n" @@ -316,7 +293,6 @@ }, { "cell_type": "markdown", - "id": "a8fdec44", "metadata": {}, "source": [ "### Qualitative" @@ -325,7 +301,6 @@ { "cell_type": "code", "execution_count": null, - "id": "6b55af78", "metadata": { "pycharm": { "name": "#%%\n" @@ -339,7 +314,6 @@ }, { "cell_type": "markdown", - "id": "05be31ed", "metadata": {}, "source": [ "### Qualitative from Sequential (or any other type of colormap)" @@ -348,7 +322,6 @@ { "cell_type": "code", "execution_count": null, - "id": "e04ab5cc", "metadata": { "pycharm": { "name": "#%%\n" @@ -362,7 +335,6 @@ }, { "cell_type": "markdown", - "id": "1fefc3d0", "metadata": {}, "source": [ "## Colors for line plots\n", @@ -374,7 +346,6 @@ }, { "cell_type": "markdown", - "id": "180de1ee", "metadata": {}, "source": [ "### Setting the colors explicitly" @@ -383,7 +354,6 @@ { "cell_type": "code", "execution_count": null, - "id": "19301803", "metadata": {}, "outputs": [], "source": [ @@ -395,7 +365,6 @@ }, { "cell_type": "markdown", - "id": "9c2ed418", "metadata": { "pycharm": { "name": "#%% md\n" @@ -408,7 +377,6 @@ { "cell_type": "code", "execution_count": null, - "id": "06f17d34", "metadata": { "pycharm": { "name": "#%%\n" @@ -427,7 +395,6 @@ { "cell_type": "code", "execution_count": null, - "id": "1b82d2dd", "metadata": { "pycharm": { "name": "#%%\n" @@ -443,7 +410,6 @@ }, { "cell_type": "markdown", - "id": "356e1096", "metadata": { "pycharm": { "name": "#%% md\n" @@ -456,7 +422,6 @@ { "cell_type": "code", "execution_count": null, - "id": "df149647", "metadata": { "pycharm": { "name": "#%%\n" @@ -477,7 +442,6 @@ { "cell_type": "code", "execution_count": null, - "id": "ae6c0f33", "metadata": { "pycharm": { "name": "#%%\n" @@ -498,7 +462,6 @@ { "cell_type": "code", "execution_count": null, - "id": "5d0483f6", "metadata": { "pycharm": { "name": "#%%\n" @@ -520,7 +483,6 @@ { "cell_type": "code", "execution_count": null, - "id": "445ab842", "metadata": { "pycharm": { "name": "#%%\n" @@ -537,7 +499,6 @@ { "cell_type": "code", "execution_count": null, - "id": "4c1bf526", "metadata": { "pycharm": { "name": "#%%\n" @@ -556,9 +517,31 @@ " axs.plot(x, y2 + a)" ] }, + { + "cell_type": "code", + "execution_count": null, + "metadata": { + "pycharm": { + "name": "#%%\n" + } + }, + "outputs": [], + "source": [ + "# Plotting stacked data with custom sampled colors and cycler\n", + "A = np.stack([x, y1, y2]).T\n", + "\n", + "cs = [plt.get_cmap('viridis')(x) for x in np.linspace(0.1, 0.5, 3)]\n", + "\n", + "fig, axs = plt.subplots(1, 1, figsize=(8, 6), facecolor='w', edgecolor='k')\n", + "\n", + "axs.set_prop_cycle(cycler('color', cs) +\n", + " cycler('linestyle', ['-', '--', ':']))\n", + "\n", + "axs.plot(x, A)" + ] + }, { "cell_type": "markdown", - "id": "cff1e2ec", "metadata": {}, "source": [ "## Colors for pseudo-color plots\n" @@ -567,7 +550,6 @@ { "cell_type": "code", "execution_count": null, - "id": "e96c82c2", "metadata": { "pycharm": { "name": "#%%\n" @@ -586,7 +568,6 @@ { "cell_type": "code", "execution_count": null, - "id": "cf7e3689", "metadata": { "pycharm": { "name": "#%%\n" @@ -606,7 +587,6 @@ { "cell_type": "code", "execution_count": null, - "id": "90955b42", "metadata": { "pycharm": { "name": "#%%\n" @@ -626,7 +606,6 @@ }, { "cell_type": "markdown", - "id": "37b0ba34", "metadata": {}, "source": [ "# Section 3: Normalization of Data\n", @@ -638,7 +617,6 @@ { "cell_type": "code", "execution_count": null, - "id": "b4e69d54", "metadata": { "pycharm": { "name": "#%%\n" @@ -660,7 +638,6 @@ { "cell_type": "code", "execution_count": null, - "id": "a8733f76", "metadata": {}, "outputs": [], "source": [ @@ -668,7 +645,7 @@ "fig, axs = plt.subplots(1, 1, figsize=(8, 6), facecolor='w', edgecolor='k')\n", "cb = axs.pcolormesh(X, Y, Z,\n", " shading='auto',\n", - " cmap=plt.get_cmap('RdBu'))\n", + " cmap=plt.get_cmap('RdBu_r'))\n", "\n", "# adding the colorbar\n", "cbar = fig.colorbar(cb, ax=axs,\n", @@ -679,7 +656,6 @@ { "cell_type": "code", "execution_count": null, - "id": "2c208e7e", "metadata": { "pycharm": { "name": "#%%\n" @@ -695,7 +671,7 @@ "cb = axs.pcolormesh(X, Y, Z,\n", " shading='auto',\n", " norm=norm,\n", - " cmap=plt.get_cmap('RdBu'))\n", + " cmap=plt.get_cmap('RdBu_r'))\n", "\n", "# adding the colorbar\n", "cbar = fig.colorbar(cb, ax=axs,\n", @@ -706,7 +682,6 @@ { "cell_type": "code", "execution_count": null, - "id": "e3cb63c7", "metadata": { "pycharm": { "name": "#%%\n" @@ -720,7 +695,7 @@ " shading='auto',\n", " vmin=-data_max,\n", " vmax=data_max,\n", - " cmap=plt.get_cmap('RdBu'))\n", + " cmap=plt.get_cmap('RdBu_r'))\n", "\n", "# adding the colorbar\n", "cbar = fig.colorbar(cb, ax=axs,\n", @@ -731,7 +706,6 @@ { "cell_type": "code", "execution_count": null, - "id": "3116095f", "metadata": { "pycharm": { "name": "#%%\n" @@ -746,7 +720,7 @@ "cb = axs.pcolormesh(X, Y, Z,\n", " shading='auto',\n", " norm=norm,\n", - " cmap=plt.get_cmap('RdBu'))\n", + " cmap=plt.get_cmap('RdBu_r'))\n", "\n", "# adding the colorbar\n", "cbar = fig.colorbar(cb, ax=axs,\n", @@ -757,7 +731,6 @@ { "cell_type": "code", "execution_count": null, - "id": "6c9bcccc", "metadata": { "pycharm": { "name": "#%%\n" @@ -783,7 +756,7 @@ "cb = axs.pcolormesh(X, Y, Z,\n", " shading='auto',\n", " norm=norm,\n", - " cmap=plt.get_cmap('RdBu'))\n", + " cmap=plt.get_cmap('RdBu_r'))\n", "\n", "# adding the colorbar\n", "cbar = fig.colorbar(cb, ax=axs,\n", @@ -794,7 +767,6 @@ { "cell_type": "code", "execution_count": null, - "id": "4ffec53b", "metadata": { "pycharm": { "name": "#%%\n" @@ -803,7 +775,7 @@ "outputs": [], "source": [ "# we can also specify descrete bounds for the mapping\n", - "cmap = plt.get_cmap('RdBu')\n", + "cmap = plt.get_cmap('RdBu_r')\n", "\n", "bounds = [-0.25, -0.1, 0.0, 0.1, 0.25]\n", "norm = mpl.colors.BoundaryNorm(bounds, cmap.N, extend='both')\n", @@ -819,7 +791,6 @@ }, { "cell_type": "markdown", - "id": "3bbac13e", "metadata": {}, "source": [ "### Excercises\n", @@ -840,8 +811,7 @@ }, { "cell_type": "code", - "execution_count": 55, - "id": "50666eea", + "execution_count": null, "metadata": { "pycharm": { "name": "#%%\n" @@ -851,9 +821,7 @@ "source": [ "X, Y = np.meshgrid(np.linspace(-5, 5, 100, endpoint=True),\n", " np.linspace(-5, 5, 100, endpoint=True))\n", - "Z = np.sin(X) * np.cos(Y) + 1\n", - "\n", - "\n" + "Z = np.sin(X) * np.cos(Y) + 0.5" ] } ], @@ -873,9 +841,9 @@ "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", - "version": "3.9.7" + "version": "3.6.9" } }, "nbformat": 4, "nbformat_minor": 5 -} \ No newline at end of file +}