Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add HexTiles element #2482

Merged
merged 20 commits into from
Mar 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions examples/gallery/demos/bokeh/hextile_movie_ratings.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import holoviews as hv\n",
"hv.extension('bokeh')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Define data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sqlite3\n",
"from bokeh.sampledata import movies_data\n",
"\n",
"# Load data\n",
"conn = sqlite3.connect(movies_data.movie_path)\n",
"movies = pd.read_sql('SELECT userRating, imdbRating FROM omdb, tomatoes WHERE omdb.ID = tomatoes.ID', conn)\n",
"\n",
"# Declare element\n",
"hextiles = hv.HexTiles(movies, [('userRating', 'Tomato User Rating'), ('imdbRating', 'IMDb Rating')], [])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"hextiles.options(width=500, height=500, min_count=0) * hv.Bivariate(hextiles).options(show_legend=False)"
]
}
],
"metadata": {
"language_info": {
"name": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
65 changes: 65 additions & 0 deletions examples/gallery/demos/matplotlib/hextile_movie_ratings.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import holoviews as hv\n",
"hv.extension('matplotlib')\n",
"%output fig='svg' size=200"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Define data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import sqlite3\n",
"from bokeh.sampledata import movies_data\n",
"\n",
"# Load data\n",
"conn = sqlite3.connect(movies_data.movie_path)\n",
"movies = pd.read_sql('SELECT userRating, imdbRating FROM omdb, tomatoes WHERE omdb.ID = tomatoes.ID', conn)\n",
"\n",
"# Declare element\n",
"hextiles = hv.HexTiles(movies, [('userRating', 'Tomato User Rating'), ('imdbRating', 'IMDb Rating')], [])"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Plot data"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"hextiles.options(min_count=0) * hv.Bivariate(hextiles)"
]
}
],
"metadata": {
"language_info": {
"name": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
116 changes: 116 additions & 0 deletions examples/reference/elements/bokeh/HexTiles.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### **Title**: HexTiles Element\n",
"\n",
"**Dependencies** Bokeh\n",
"\n",
"**Backends** [Bokeh](./HexTiles.ipynb), [Matplotlib]('../matplotlib/HexTiles.ipynb')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import holoviews as hv\n",
"hv.extension('bokeh')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"``HexTiles`` provide a representation of the data as a bivariate histogram useful for visualizing the structure in larger datasets. The ``HexTiles`` are computed by tesselating the x-, y-ranges of the data, storing the number of points falling in each hexagonal bin. By default ``HexTiles`` simply counts the data in each bin but it also supports weighted aggregations. Currently only linearly spaced bins are supported when using the bokeh backend.\n",
"\n",
"As a simple example we will generate 100,000 normally distributed points and plot them using ``HexTiles``:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"np.random.seed(44)\n",
"hex_tiles = hv.HexTiles(np.random.randn(100000, 2))\n",
"hex_tiles.options(width=500, height=400, tools=['hover'],\n",
" colorbar=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the hover shows a ``Count`` by default, representing the number of points falling within each bin.\n",
"\n",
"It is also possible to provide additional value dimensions and define an ``aggregator`` to aggregate by value. If multiple value dimensions are defined the dimension to be colormapped may be defined using the ``color_index``. Note however that multiple value dimensions are allowed and will be displayed in the hover tooltip."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"xs, ys = np.random.randn(2, 1000)\n",
"hex_with_values = hv.HexTiles((xs, ys, xs*(ys/2.), (xs**2)*ys), vdims=['Values', 'Hover Values'])\n",
"\n",
"hex_with_values.options(width=400, height=400, aggregator=np.sum, tools=['hover']) *\\\n",
"hv.Points(hex_with_values).options(size=1, color='black')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The bokeh backend also supports scaling the size of each hexagon by a value, which can be enabled using the ``size_index`` option. The minimum and maximum scaling can be set using the ``min_scale`` and ``max_scale`` options, defining how large the bins are relative to the size of a hexagon under uniform tiling.\n",
"\n",
"Here we will generate two separate distributions and visualize them by scaling each bin by the 'Count'."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x, y = np.hstack([np.random.randn(2, 10000), np.random.randn(2, 10000)*0.8+2])\n",
"hex_two_distributions = hv.HexTiles((x, y))\n",
"hex_two_distributions.options(size_index='Count', width=500, height=500, min_scale=0.3, max_scale=0.85)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"By default ``HexTiles`` do not plot bins that do not contain any data but using the ``min_count`` option it is possible to plot bins with zero values as well or alternatively set a higher cutoff. Using this options can result in a more visually appealing plot particularly when overlaid with other elements.\n",
"\n",
"Here we will plot the same distributions as above and overlay a ``Bivariate`` plot of the same data:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"hex_two_distributions.options(min_count=0, width=500, height=500, tools=['hover']) *\\\n",
"hv.Bivariate(hex_two_distributions).options(show_legend=False, line_width=3)"
]
}
],
"metadata": {
"language_info": {
"name": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
98 changes: 98 additions & 0 deletions examples/reference/elements/matplotlib/HexTiles.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### **Title**: HexTiles Element\n",
"\n",
"**Dependencies** Matplotlib\n",
"\n",
"**Backends** [Matplotlib](./HexTiles.ipynb), [Bokeh]('../bokeh/HexTiles.ipynb')"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"import numpy as np\n",
"import holoviews as hv\n",
"hv.extension('matplotlib')\n",
"%output fig='svg' size=200"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"``HexTiles`` provide a representation of the data as a bivariate histogram useful for visualizing the structure in larger datasets. The ``HexTiles`` are computed by tesselating the x-, y-ranges of the data, storing the number of points falling in each hexagonal bin. By default ``HexTiles`` simply counts the data in each bin but it also supports weighted aggregations. Currently only linearly spaced bins are supported when using the bokeh backend.\n",
"\n",
"As a simple example we will generate 100,000 normally distributed points and plot them using ``HexTiles``:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"np.random.seed(44)\n",
"hex_tiles = hv.HexTiles(np.random.randn(100000, 2))\n",
"hex_tiles.options(colorbar=True)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Note that the hover shows a ``Count`` by default, representing the number of points falling within each bin.\n",
"\n",
"It is also possible to provide additional value dimensions and define an ``aggregator`` to aggregate by value. If multiple value dimensions are defined the dimension to be colormapped may be defined using the ``color_index``. Note however that multiple value dimensions are allowed and will be displayed in the hover tooltip."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"xs, ys = np.random.randn(2, 1000)\n",
"hex_with_values = hv.HexTiles((xs, ys, xs*(ys/2.), (xs**2)*ys), vdims=['Values', 'Hover Values'])\n",
"\n",
"hex_with_values.options(aggregator=np.sum) *\\\n",
"hv.Points(hex_with_values).options(s=3, color='black')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"By default ``HexTiles`` do not plot bins that do not contain any data but using the ``min_count`` option it is possible to plot bins with zero values as well or alternatively set a higher cutoff. Using this options can result in a more visually appealing plot particularly when overlaid with other elements.\n",
"\n",
"Here we will plot the same distributions as above and overlay a ``Bivariate`` plot of the same data:"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"x, y = np.hstack([np.random.randn(2, 10000), np.random.randn(2, 10000)*0.8+2])\n",
"hex_two_distributions = hv.HexTiles((x, y))\n",
"hex_two_distributions.options(min_count=0) *\\\n",
"hv.Bivariate(hex_two_distributions).options(show_legend=False, linewidth=3)"
]
}
],
"metadata": {
"language_info": {
"name": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
Loading