Skip to content

Commit df97d01

Browse files
committed
Cleaning up docs [build:website_dev]
1 parent 2b51d43 commit df97d01

File tree

5 files changed

+121
-19
lines changed

5 files changed

+121
-19
lines changed

Diff for: .travis.yml

+1-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ stages:
1616
- name: package
1717
if: tag =~ ^v(\d+|\.)+[^a-z]\d+$
1818
- name: website_dev
19-
if: tag =~ ^v(\d+|\.)+[a-z]\d+$ OR tag = website_dev
19+
if: tag =~ ^v(\d+|\.)+[a-z]\d+$ OR tag = website_dev OR commit_message =~ /^.*(website_dev).*$/
2020
- name: website_release
2121
if: tag =~ ^v(\d+|\.)+[^a-z]\d+$ OR tag = website
2222

@@ -53,7 +53,6 @@ jobs:
5353
local_dir: ./builtdocs
5454
repo: pyviz-dev/contrib_colormaps
5555
on:
56-
tags: true
5756
all_branches: true
5857

5958
## dev packages

Diff for: README.md

+13-3
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,16 @@ contrib_colormaps supports Python 2.7, 3.5, 3.6 and 3.7 on Linux, Windows,
2323
or Mac and can be installed with conda:
2424

2525
```
26-
conda install contrib_colormaps
26+
conda install contrib_colormaps
2727
```
2828

2929
or with pip:
3030

3131
```
32-
pip install contrib_colormaps
32+
pip install contrib_colormaps
3333
```
3434

35-
## Contributing a colormap
35+
## Contributing
3636

3737
To add a colormap, open a pull request on this repository adding a
3838
comma-separated file of RGB values to the contrib_colormaps/colormaps
@@ -48,6 +48,16 @@ This PR should also include a new notebook in
4848
name of the csv (e.g. for a new colormap called 'rainforest' with a csv
4949
'rainforest.csv' there should be a corresponding 'rainforest.ipynb').
5050

51+
The last requirement is that you regenerate the baseline images used for tests.
52+
First make sure you have holoviews, matplotlib, and pytest-mpl in your
53+
environment. Then change directories into tests, and regenerate the plots
54+
55+
```
56+
cd contrib_colorcets/tests
57+
pytest --mpl-generate-path=baseline
58+
```
59+
60+
5161
## About PyViz
5262

5363
contrib_colormaps is part of the PyViz initiative for making Python-based

Diff for: contrib_colormaps/plotting.py

+29
Original file line numberDiff line numberDiff line change
@@ -31,3 +31,32 @@ def swatch(name, bounds=None, array=array, **kwargs):
3131
plot.opts(opts.Image(backend='matplotlib', aspect=aspect, fig_size=fig_size,
3232
cmap=cm[name]))
3333
return plot.opts(opts.Image(xaxis=None, yaxis=None), opts.Image(**kwargs))
34+
35+
36+
def swatches(names=None, cols=None, **kwargs):
37+
"""Show swatches for all names or given names"""
38+
if not names:
39+
names = sorted([name for name in palette.keys()])
40+
41+
if not cols:
42+
cols = 2 if len(names) >= 2 else 1
43+
44+
backends = hv.Store.loaded_backends()
45+
if 'matplotlib' in backends:
46+
if 'aspect' not in kwargs:
47+
kwargs['aspect'] = 12 // cols
48+
if 'fig_size' not in kwargs:
49+
kwargs['fig_size'] = 500 // cols
50+
if 'bokeh' in backends:
51+
if 'height' not in kwargs:
52+
kwargs['height'] = 100
53+
if 'width' not in kwargs:
54+
kwargs['width'] = (9 * kwargs['height']) // cols
55+
56+
images = [swatch(name, **kwargs) for name in names]
57+
plot = hv.Layout(images).opts(plot=dict(transpose=True)).cols(int(np.ceil(len(images)*1.0/cols)))
58+
59+
if 'matplotlib' in backends:
60+
plot.opts(opts.Layout(backend='matplotlib', sublabel_format=None,
61+
fig_size=kwargs.get('fig_size', 150)))
62+
return plot

Diff for: examples/colormaps/index.ipynb

+63-13
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
"source": [
77
"## Accessing the colormaps\n",
88
"\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",
1010
"\n",
1111
"1. A Bokeh-style palette, i.e., a Python list of RGB colors as hex strings, like ``['#000000', ..., '#ffffff']``\n",
1212
"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",
1313
"\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",
1515
"\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\"]``."
1717
]
1818
},
1919
{
@@ -22,13 +22,15 @@
2222
"source": [
2323
"#### Example\n",
2424
"\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. "
2626
]
2727
},
2828
{
2929
"cell_type": "code",
3030
"execution_count": null,
31-
"metadata": {},
31+
"metadata": {
32+
"scrolled": true
33+
},
3234
"outputs": [],
3335
"source": [
3436
"import contrib_colormaps as cc\n",
@@ -42,27 +44,67 @@
4244
"source": [
4345
"## Plotting\n",
4446
"\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')"
4674
]
4775
},
4876
{
4977
"cell_type": "markdown",
5078
"metadata": {},
5179
"source": [
52-
"#### Example\n",
80+
"## Usage\n",
5381
"\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"
5585
]
5686
},
5787
{
5888
"cell_type": "code",
5989
"execution_count": null,
60-
"metadata": {},
90+
"metadata": {
91+
"scrolled": true
92+
},
6193
"outputs": [],
6294
"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"
66108
]
67109
},
68110
{
@@ -71,7 +113,15 @@
71113
"metadata": {},
72114
"outputs": [],
73115
"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)"
75125
]
76126
}
77127
],

Diff for: examples/index.ipynb

+15-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,21 @@
1212
"[Matplotlib](http://matplotlib.org),\n",
1313
"[HoloViews](http://holoviews.org), and\n",
1414
"[Datashader](https://github.com/pyviz/datashader). \n",
15-
"\n"
15+
"\n",
16+
"Below are all the colormaps in the current version of the library. To contribute a new colormap, see the contributing section of the [README](https://github.com/pyviz/contrib_colormaps#contributing). To learn more about how to use the various colormaps and what each is for, see the [colormaps section](colormaps/index.ipynb)."
17+
]
18+
},
19+
{
20+
"cell_type": "code",
21+
"execution_count": null,
22+
"metadata": {},
23+
"outputs": [],
24+
"source": [
25+
"from contrib_colormaps.plotting import swatches\n",
26+
"import holoviews as hv\n",
27+
"hv.extension('bokeh', logo=False)\n",
28+
"\n",
29+
"swatches()"
1630
]
1731
}
1832
],

0 commit comments

Comments
 (0)