Skip to content

Commit

Permalink
Added example of using the alpha channel for RGB and sat,val for HSV
Browse files Browse the repository at this point in the history
  • Loading branch information
James A. Bednar committed Feb 24, 2015
1 parent bd3b4e1 commit 052b15c
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions doc/Tutorials/Elements.ipynb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"metadata": {
"name": "",
"signature": "sha256:b9b1acdc08f084d5be79ddba0f44dd549fa28658f9fd62a5a477b04dac6fbab2"
"signature": "sha256:ee05551878dd1f836aa85776b2de474ce32f149d9cc5b82a0311ffbdf9ade72e"
},
"nbformat": 3,
"nbformat_minor": 0,
Expand Down Expand Up @@ -522,7 +522,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"A ``HeatMap`` displays like a typical raster image, but the input is a dictionary indexed with two-dimensional keys, not a Numpy array. As many rows and columns as required will be created to display the values in an appropriate grid format. Values unspecified are left blank, and the keys can be any Python datatype (not necessarily numeric). One typical usage is to show values from a set of experiments, such as a parameter space exploration, and many other such visualizations are shown in the [Containers](Containers.html) and [Exploring Data](Exploring_Data.html) tutorials. Each value in a ``HeatMap`` is labeled explicitly , and so this component is not meant for very large numbers of samples."
"A ``HeatMap`` displays like a typical raster image, but the input is a dictionary indexed with two-dimensional keys, not a Numpy array. As many rows and columns as required will be created to display the values in an appropriate grid format. Values unspecified are left blank, and the keys can be any Python datatype (not necessarily numeric). One typical usage is to show values from a set of experiments, such as a parameter space exploration, and many other such visualizations are shown in the [Containers](Containers.html) and [Exploring Data](Exploring_Data.html) tutorials. Each value in a ``HeatMap`` is labeled explicitly , and so this component is not meant for very large numbers of samples. With the default color map, high values (in the upper half of the range present) are colored orange and red, while low values (in the lower half of the range present) are colored shades of blue."
]
},
{
Expand Down Expand Up @@ -591,23 +591,46 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"The ``RGB`` element is an ``Image`` that supports red, green, blue, and optionally an alpha channel."
"The ``RGB`` element is an ``Image`` that supports red, green, blue channels:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"import numpy as np\n",
"from holoviews import RGB\n",
"from holoviews import RGB, Image, VLine\n",
"\n",
"x,y = np.mgrid[-50:51, -50:51] * 0.1\n",
"r = 0.5*np.sin(np.pi +x**2+y**2)+0.5\n",
"\n",
"r = 0.5*np.sin(np.pi +3*x**2+y**2)+0.5\n",
"g = 0.5*np.sin(np.pi/2+x**2+y**2)+0.5\n",
"b = 0.5*np.sin(x**2+y**2)+0.5\n",
"a = 0.5*np.sin(0.2*(x**2+y**2))+0.5\n",
"b = 0.5*np.sin(x**2+2*y**2)+0.5\n",
"\n",
"rgb = RGB(np.dstack([r,g,b]))\n",
"rgb"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"``RGB`` also supports an optional alpha channel, which will be used as a mask revealing or hiding the underlying ``Elements``:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"%%opts Image (cmap='gray')\n",
"mask = 0.5*np.sin(0.2*(x**2+y**2))+0.5\n",
"grating = 0.5*np.cos(x*3)+0.5\n",
"bg = Image(grating)*VLine(x=0)\n",
"\n",
"RGB(np.dstack([r,g,b])) + RGB(np.dstack([r,g,b,a]))"
"bg + Image(mask) + bg*RGB(np.dstack([r,g,b,mask]))"
],
"language": "python",
"metadata": {},
Expand Down Expand Up @@ -637,8 +660,8 @@
"\n",
"x,y = np.mgrid[-50:51, -50:51] * 0.1\n",
"h = 0.5 + np.sin(0.2*(x**2+y**2)) / 2.0\n",
"s = 0.5 + np.cos(0.2*(x**2+y**2)) / 2.0\n",
"v = np.ones((101,101))\n",
"s = 0.5*np.cos(y*3)+0.5\n",
"v = 0.5*np.cos(x*3)+0.5\n",
"\n",
"HSV(np.dstack([h, s, v]))"
],
Expand Down

0 comments on commit 052b15c

Please sign in to comment.