|
6 | 6 | "source": [
|
7 | 7 | "## Accessing the colormaps\n",
|
8 | 8 | "\n",
|
9 |
| - "After importing `contrib_colormaps` as `cc`, all the colormaps shown in this notebook will be available for use in different forms. It's a bit difficult to describe, but the idea is that this library should have at least one such form convenient for any particular application. There are two different basic versions for each colormap, each of which is fundamentally a list of colors: \n", |
| 9 | + "After importing `contrib_colormaps` as `cc`, all the colormaps will be available for use in different forms. It's a bit difficult to describe, but the idea is that this library should have at least one such form convenient for any particular application. There are two different basic versions for each colormap, each of which is fundamentally a list of colors: \n", |
10 | 10 | "\n",
|
11 | 11 | "1. A Bokeh-style palette, i.e., a Python list of RGB colors as hex strings, like ``['#000000', ..., '#ffffff']``\n",
|
12 | 12 | "2. If matplotlib is installed and importable, a Matplotlib ``LinearSegmentedColormap`` using normalized magnitudes, like ``LinearSegmentedColormap.from_list(\"fire\",[ [0.0,0.0,0.0], ..., [1.0,1.0,1.0] ], 256)``\n",
|
13 | 13 | "\n",
|
14 |
| - "The Bokeh-compatible palettes are provided as attributes in the ``contrib_colormaps`` namespace, with long names prefixed with ``b_``. E.g. ``rainforest`` can be accessed as ``cc.b_rainforest``. These names should tab complete once ``cc`` has been imported. Because Bokeh palettes are just Python lists, you can always reverse them using normal Python syntax, e.g. ``list(reversed(cc.b_rainforest))``, or use subsets of them with slice notation, e.g. ``cc.b_rainforest[25:]``. If you want to access the palettes by string name, they are also collected into a dictionary named ``palette``, so you can use ``cc.palette[\"rainforest\"]`` or ``cc.palette.rainforest``; whichever is more convenient.\n", |
| 14 | + "The Bokeh-compatible palettes are provided as attributes in the ``contrib_colormaps`` namespace, with long names prefixed with ``b_``. E.g. ``rainforest`` can be accessed as ``cc.b_sample``. These names should tab complete once ``cc`` has been imported. Because Bokeh palettes are just Python lists, you can always reverse them using normal Python syntax, e.g. ``list(reversed(cc.b_sample))``, or use subsets of them with slice notation, e.g. ``cc.b_sample[25:]``. If you want to access the palettes by string name, they are also collected into a dictionary named ``palette``, so you can use ``cc.palette[\"sample\"]`` or ``cc.palette.sample``; whichever is more convenient.\n", |
15 | 15 | "\n",
|
16 |
| - "The Matplotlib colormaps are also provided as tab-completable attributes, but consistently with a prefix ``m_``, e.g. ``cc.m_rainforest``. Already reversed versions are also available, as ``cc.m_rainforest_r``. The same colormaps are also registered with matplotlib's string-based dictionary with the prefix ``cc_``, making them available by name within various matplotlib functions (e.g. ``cc_rainforest``, ``cc_rainforest_r``). Finally, if you want to access the colormaps by string name without using Matplotlib's registry, they are also stored in the ``cc.cm`` dictionary, e.g. ``cc.cm[\"rainforest\"]`` or ``cc.cm[\"rainforest_r\"]``.\n" |
| 16 | + "The Matplotlib colormaps are also provided as tab-completable attributes, but consistently with a prefix ``m_``, e.g. ``cc.m_sample``. Already reversed versions are also available, as ``cc.m_sample_r``. The same colormaps are also registered with matplotlib's string-based dictionary with the prefix ``cc_``, making them available by name within various matplotlib functions (e.g. ``cc_sample``, ``cc_sample_r``). Finally, if you want to access the colormaps by string name without using Matplotlib's registry, they are also stored in the ``cc.cm`` dictionary, e.g. ``cc.cm[\"sample\"]`` or ``cc.cm[\"sample_r\"]``." |
17 | 17 | ]
|
18 | 18 | },
|
19 | 19 | {
|
|
22 | 22 | "source": [
|
23 | 23 | "#### Example\n",
|
24 | 24 | "\n",
|
25 |
| - "Here we show importing rainforest and printing the first 5 colors in the set. " |
| 25 | + "Here we show importing sample and printing the first 5 colors. " |
26 | 26 | ]
|
27 | 27 | },
|
28 | 28 | {
|
29 | 29 | "cell_type": "code",
|
30 | 30 | "execution_count": null,
|
31 |
| - "metadata": {}, |
| 31 | + "metadata": { |
| 32 | + "scrolled": true |
| 33 | + }, |
32 | 34 | "outputs": [],
|
33 | 35 | "source": [
|
34 | 36 | "import contrib_colormaps as cc\n",
|
|
42 | 44 | "source": [
|
43 | 45 | "## Plotting\n",
|
44 | 46 | "\n",
|
45 |
| - "For ease of use, we also provide minimal plotting commands for use with contrib_colormaps. These depend on holoviews, which needs to be installed before they can be used. Once set up, these commands provide easy viewing capability of the colormaps." |
| 47 | + "For ease of use, we also provide minimal plotting commands for use with contrib_colormaps. These depend on holoviews, which needs to be installed before they can be used. Once set up, these commands provide easy viewing capability of the colormaps.\n", |
| 48 | + "\n", |
| 49 | + "#### Example\n", |
| 50 | + "\n", |
| 51 | + "Import `swatch` from `contrib_colormaps.plotting` and load your desired backend into holoviews. Then call `swatch` with the name of a colormap. " |
| 52 | + ] |
| 53 | + }, |
| 54 | + { |
| 55 | + "cell_type": "code", |
| 56 | + "execution_count": null, |
| 57 | + "metadata": {}, |
| 58 | + "outputs": [], |
| 59 | + "source": [ |
| 60 | + "from contrib_colormaps.plotting import swatch, swatches\n", |
| 61 | + "import holoviews as hv\n", |
| 62 | + "hv.extension('bokeh', 'matplotlib', logo=False)" |
| 63 | + ] |
| 64 | + }, |
| 65 | + { |
| 66 | + "cell_type": "code", |
| 67 | + "execution_count": null, |
| 68 | + "metadata": { |
| 69 | + "scrolled": true |
| 70 | + }, |
| 71 | + "outputs": [], |
| 72 | + "source": [ |
| 73 | + "swatch('sample')" |
46 | 74 | ]
|
47 | 75 | },
|
48 | 76 | {
|
49 | 77 | "cell_type": "markdown",
|
50 | 78 | "metadata": {},
|
51 | 79 | "source": [
|
52 |
| - "#### Example\n", |
| 80 | + "## Usage\n", |
53 | 81 | "\n",
|
54 |
| - "Import `swatch` from `contrib_colormaps.plotting` and load your desired backend into holoviews. Then call `swatch` with the name of a colormap. " |
| 82 | + "All of the colormaps can be used directly in plotting libraries such as matplotlib or bokeh.\n", |
| 83 | + "\n", |
| 84 | + "#### Matplotlib" |
55 | 85 | ]
|
56 | 86 | },
|
57 | 87 | {
|
58 | 88 | "cell_type": "code",
|
59 | 89 | "execution_count": null,
|
60 |
| - "metadata": {}, |
| 90 | + "metadata": { |
| 91 | + "scrolled": true |
| 92 | + }, |
61 | 93 | "outputs": [],
|
62 | 94 | "source": [
|
63 |
| - "from contrib_colormaps.plotting import swatch\n", |
64 |
| - "import holoviews as hv\n", |
65 |
| - "hv.extension('matplotlib')" |
| 95 | + "import numpy as np\n", |
| 96 | + "import contrib_colormaps as cc\n", |
| 97 | + "import matplotlib.pyplot as plt\n", |
| 98 | + "\n", |
| 99 | + "xs, _ = np.meshgrid(np.linspace(0, 1, 80), np.linspace(0, 1, 10))\n", |
| 100 | + "plt.imshow(xs, cmap=cc.cm.sample); # use tab completion to choose" |
| 101 | + ] |
| 102 | + }, |
| 103 | + { |
| 104 | + "cell_type": "markdown", |
| 105 | + "metadata": {}, |
| 106 | + "source": [ |
| 107 | + "#### Bokeh" |
66 | 108 | ]
|
67 | 109 | },
|
68 | 110 | {
|
|
71 | 113 | "metadata": {},
|
72 | 114 | "outputs": [],
|
73 | 115 | "source": [
|
74 |
| - "swatch('sample')" |
| 116 | + "import numpy as np\n", |
| 117 | + "import contrib_colormaps as cc\n", |
| 118 | + "from bokeh.plotting import figure, show\n", |
| 119 | + "\n", |
| 120 | + "xs, _ = np.meshgrid(np.linspace(0, 1, 80), np.linspace(0, 1, 10))\n", |
| 121 | + "p = figure(x_range=(0, 80), y_range=(0, 10), height=100, width=400)\n", |
| 122 | + "\n", |
| 123 | + "p.image(image=[xs], x=0, y=0, dw=80, dh=10, palette=cc.palette.sample) # use tab completion to choose\n", |
| 124 | + "show(p)" |
75 | 125 | ]
|
76 | 126 | }
|
77 | 127 | ],
|
|
0 commit comments