"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import holoviews as hv\n",
"hv.extension('plotly')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A ``GridSpace`` is a two-dimensional dictionary of HoloViews objects presented onscreen as a grid. In one sense, due to the restriction on its dimensionality, a ``GridSpace`` may be considered a special case of [``HoloMap``](./HoloMap.ipynb). In another sense, ``GridSpace`` may be seen as more general as a ``GridSpace`` can hold a ``HoloMap`` but the converse is not permitted; see the [Building Composite Objects](../../../user_guide/06-Building_Composite_Objects.ipynb) user guide for details on how to compose containers."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### ``GridSpace`` holds two-dimensional dictionaries"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Using the ``sine_curve`` function below, we can declare a two-dimensional dictionary of ``Curve`` elements, where the keys are 2-tuples corresponding to (phase, frequency) values:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"def sine_curve(phase, freq):\n",
" xvals = [0.1* i for i in range(100)]\n",
" return hv.Curve((xvals, [np.sin(phase+freq*x) for x in xvals]))\n",
"\n",
"phases = [0, np.pi/2, np.pi, 3*np.pi/2]\n",
"frequencies = [0.5, 0.75, 1.0, 1.25]\n",
"curve_dict_2D = {(p,f):sine_curve(p,f) for p in phases for f in frequencies}"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can now pass this dictionary of curves to ``GridSpace``:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"gridspace = hv.GridSpace(curve_dict_2D, kdims=['phase', 'frequency'])\n",
"gridspace"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### ``GridSpace`` is similar to ``HoloMap``"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Other than the difference in the visual semantics, whereby ``GridSpaces`` display their contents together in a two-dimensional grid, ``GridSpaces`` are very similar to ``HoloMap``s (see the [``HoloMap``](./HoloMap.ipynb) notebook for more information).\n",
"\n",
"One way to demonstrate the similarity of these two containers is to cast our ``gridspace`` object to ``HoloMap`` and back to a ``GridSpace``:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"hmap = hv.HoloMap(gridspace)\n",
"hmap + hv.GridSpace(hmap)"
]
}
],
"metadata": {
"language_info": {
"name": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}