Skip to content

Commit

Permalink
Cleaning up docs [build:website_dev]
Browse files Browse the repository at this point in the history
  • Loading branch information
jsignell committed Oct 14, 2019
1 parent 2b51d43 commit df97d01
Show file tree
Hide file tree
Showing 5 changed files with 121 additions and 19 deletions.
3 changes: 1 addition & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ stages:
- name: package
if: tag =~ ^v(\d+|\.)+[^a-z]\d+$
- name: website_dev
if: tag =~ ^v(\d+|\.)+[a-z]\d+$ OR tag = website_dev
if: tag =~ ^v(\d+|\.)+[a-z]\d+$ OR tag = website_dev OR commit_message =~ /^.*(website_dev).*$/
- name: website_release
if: tag =~ ^v(\d+|\.)+[^a-z]\d+$ OR tag = website

Expand Down Expand Up @@ -53,7 +53,6 @@ jobs:
local_dir: ./builtdocs
repo: pyviz-dev/contrib_colormaps
on:
tags: true
all_branches: true

## dev packages
Expand Down
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ contrib_colormaps supports Python 2.7, 3.5, 3.6 and 3.7 on Linux, Windows,
or Mac and can be installed with conda:

```
conda install contrib_colormaps
conda install contrib_colormaps
```

or with pip:

```
pip install contrib_colormaps
pip install contrib_colormaps
```

## Contributing a colormap
## Contributing

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

The last requirement is that you regenerate the baseline images used for tests.
First make sure you have holoviews, matplotlib, and pytest-mpl in your
environment. Then change directories into tests, and regenerate the plots

```
cd contrib_colorcets/tests
pytest --mpl-generate-path=baseline
```


## About PyViz

contrib_colormaps is part of the PyViz initiative for making Python-based
Expand Down
29 changes: 29 additions & 0 deletions contrib_colormaps/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,32 @@ def swatch(name, bounds=None, array=array, **kwargs):
plot.opts(opts.Image(backend='matplotlib', aspect=aspect, fig_size=fig_size,
cmap=cm[name]))
return plot.opts(opts.Image(xaxis=None, yaxis=None), opts.Image(**kwargs))


def swatches(names=None, cols=None, **kwargs):
"""Show swatches for all names or given names"""
if not names:
names = sorted([name for name in palette.keys()])

if not cols:
cols = 2 if len(names) >= 2 else 1

backends = hv.Store.loaded_backends()
if 'matplotlib' in backends:
if 'aspect' not in kwargs:
kwargs['aspect'] = 12 // cols
if 'fig_size' not in kwargs:
kwargs['fig_size'] = 500 // cols
if 'bokeh' in backends:
if 'height' not in kwargs:
kwargs['height'] = 100
if 'width' not in kwargs:
kwargs['width'] = (9 * kwargs['height']) // cols

images = [swatch(name, **kwargs) for name in names]
plot = hv.Layout(images).opts(plot=dict(transpose=True)).cols(int(np.ceil(len(images)*1.0/cols)))

if 'matplotlib' in backends:
plot.opts(opts.Layout(backend='matplotlib', sublabel_format=None,
fig_size=kwargs.get('fig_size', 150)))
return plot
76 changes: 63 additions & 13 deletions examples/colormaps/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@
"source": [
"## Accessing the colormaps\n",
"\n",
"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",
"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",
"\n",
"1. A Bokeh-style palette, i.e., a Python list of RGB colors as hex strings, like ``['#000000', ..., '#ffffff']``\n",
"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",
"\n",
"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",
"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",
"\n",
"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"
"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\"]``."
]
},
{
Expand All @@ -22,13 +22,15 @@
"source": [
"#### Example\n",
"\n",
"Here we show importing rainforest and printing the first 5 colors in the set. "
"Here we show importing sample and printing the first 5 colors. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"import contrib_colormaps as cc\n",
Expand All @@ -42,27 +44,67 @@
"source": [
"## Plotting\n",
"\n",
"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."
"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",
"\n",
"#### Example\n",
"\n",
"Import `swatch` from `contrib_colormaps.plotting` and load your desired backend into holoviews. Then call `swatch` with the name of a colormap. "
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from contrib_colormaps.plotting import swatch, swatches\n",
"import holoviews as hv\n",
"hv.extension('bokeh', 'matplotlib', logo=False)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"swatch('sample')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Example\n",
"## Usage\n",
"\n",
"Import `swatch` from `contrib_colormaps.plotting` and load your desired backend into holoviews. Then call `swatch` with the name of a colormap. "
"All of the colormaps can be used directly in plotting libraries such as matplotlib or bokeh.\n",
"\n",
"#### Matplotlib"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"metadata": {
"scrolled": true
},
"outputs": [],
"source": [
"from contrib_colormaps.plotting import swatch\n",
"import holoviews as hv\n",
"hv.extension('matplotlib')"
"import numpy as np\n",
"import contrib_colormaps as cc\n",
"import matplotlib.pyplot as plt\n",
"\n",
"xs, _ = np.meshgrid(np.linspace(0, 1, 80), np.linspace(0, 1, 10))\n",
"plt.imshow(xs, cmap=cc.cm.sample); # use tab completion to choose"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Bokeh"
]
},
{
Expand All @@ -71,7 +113,15 @@
"metadata": {},
"outputs": [],
"source": [
"swatch('sample')"
"import numpy as np\n",
"import contrib_colormaps as cc\n",
"from bokeh.plotting import figure, show\n",
"\n",
"xs, _ = np.meshgrid(np.linspace(0, 1, 80), np.linspace(0, 1, 10))\n",
"p = figure(x_range=(0, 80), y_range=(0, 10), height=100, width=400)\n",
"\n",
"p.image(image=[xs], x=0, y=0, dw=80, dh=10, palette=cc.palette.sample) # use tab completion to choose\n",
"show(p)"
]
}
],
Expand Down
16 changes: 15 additions & 1 deletion examples/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,21 @@
"[Matplotlib](http://matplotlib.org),\n",
"[HoloViews](http://holoviews.org), and\n",
"[Datashader](https://github.com/pyviz/datashader). \n",
"\n"
"\n",
"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)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from contrib_colormaps.plotting import swatches\n",
"import holoviews as hv\n",
"hv.extension('bokeh', logo=False)\n",
"\n",
"swatches()"
]
}
],
Expand Down

0 comments on commit df97d01

Please sign in to comment.