Skip to content

Commit

Permalink
Merge pull request #710 from rossant/fix-colormap-examples
Browse files Browse the repository at this point in the history
Fixed colormap example notebooks
  • Loading branch information
larsoner committed Jan 20, 2015
2 parents ec1fe84 + eb1b38f commit 608be1b
Show file tree
Hide file tree
Showing 2 changed files with 161 additions and 144 deletions.
303 changes: 160 additions & 143 deletions examples/ipynb/colormaps.ipynb
Original file line number Diff line number Diff line change
@@ -1,146 +1,163 @@
{
"metadata": {
"name": "",
"signature": "sha256:45db16e59de79e2b845ae3044ac5af9e7c77ea71efa482fb1ace177b30a1f137"
},
"nbformat": 3,
"nbformat_minor": 0,
"worksheets": [
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# VisPy colormaps"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook illustrates the colormap API provided by VisPy."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## List all colormaps"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"import numpy as np\n",
"from vispy.color import (get_colormap, get_colormaps, Colormap)\n",
"from IPython.display import display_html"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"for cmap in get_colormaps():\n",
" display_html('<h3>%s</h3>' % cmap, raw=True)\n",
" display_html(get_colormap(cmap))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Discrete colormaps"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Discrete colormaps can be created by giving a list of colors, and an optional list of control points (in $[0,1]$, the first and last points need to be $0$ and $1$ respectively). The colors can be specified in many ways (1-character shortcuts, hexadecimal values, arrays or RGB values, `ColorArray` instances, and so on)."
]
},
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# VisPy colormaps"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This notebook illustrates the colormap API provided by VisPy."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## List all colormaps"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import numpy as np\n",
"from vispy.color import (get_colormap, get_colormaps, Colormap)\n",
"from IPython.display import display_html"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"for cmap in get_colormaps():\n",
" display_html('<h3>%s</h3>' % cmap, raw=True)\n",
" display_html(get_colormap(cmap))"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Discrete colormaps"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Discrete colormaps can be created by giving a list of colors, and an optional list of control points (in $[0,1]$, the first and last points need to be $0$ and $1$ respectively). The colors can be specified in many ways (1-character shortcuts, hexadecimal values, arrays or RGB values, `ColorArray` instances, and so on)."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"Colormap(['r', 'g', 'b'], interpolation='discrete')"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"Colormap(['r', 'g', 'y'], interpolation='discrete')"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"Colormap(np.array([[0, .75, 0],\n",
" [.75, .25, .5]]), \n",
" [0., .25, 1.], \n",
" interpolation='discrete')"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"Colormap(['r', 'g', '#123456'],\n",
" interpolation='discrete')"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Linear gradients"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"Colormap(['r', 'g', '#123456'])"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"Colormap([[1,0,0], [1,1,1], [1,0,1]], \n",
" [0., .75, 1.])"
],
"language": "python",
"metadata": {},
"outputs": []
}
],
"metadata": {}
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"Colormap(['r', 'g', 'b'], interpolation='zero')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"Colormap(['r', 'g', 'y'], interpolation='zero')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"Colormap(np.array([[0, .75, 0],\n",
" [.75, .25, .5]]), \n",
" [0., .25, 1.], \n",
" interpolation='zero')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"Colormap(['r', 'g', '#123456'],\n",
" interpolation='zero')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Linear gradients"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"Colormap(['r', 'g', '#123456'])"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"collapsed": false
},
"outputs": [],
"source": [
"Colormap([[1,0,0], [1,1,1], [1,0,1]], \n",
" [0., .75, 1.])"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.4.2"
}
]
}
},
"nbformat": 4,
"nbformat_minor": 0
}
2 changes: 1 addition & 1 deletion vispy/color/colormap.py
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@ def interpolation(self):
@interpolation.setter
def interpolation(self, val):
if val not in _interpolation_info:
raise ValueError('The interpolation mode can only be one of: '
raise ValueError('The interpolation mode can only be one of: ' +
', '.join(sorted(_interpolation_info.keys())))
# Get the information of the interpolation mode.
info = _interpolation_info[val]
Expand Down

0 comments on commit 608be1b

Please sign in to comment.