Skip to content

Commit

Permalink
Merge 10d5048 into e8f3496
Browse files Browse the repository at this point in the history
  • Loading branch information
kcpevey committed Oct 22, 2020
2 parents e8f3496 + 10d5048 commit fcbc6f5
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions examples/reference/elements/bokeh/Bars.ipynb
Expand Up @@ -18,6 +18,7 @@
"outputs": [],
"source": [
"import numpy as np\n",
"import pandas as pd\n",
"import holoviews as hv\n",
"hv.extension('bokeh')"
]
Expand All @@ -44,6 +45,16 @@
"bars"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can achieve the same plot using a Pandas DataFrame:\n",
"```\n",
"hv.Bars(pd.DataFrame(data, columns=['Car occupants','Count']))\n",
"```"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down Expand Up @@ -84,7 +95,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"``Bars`` support nested categorical groupings, e.g. here we will create a random sample of pets sub-divided by male and female:"
"``Bars`` also supports nested categorical groupings. Next we'll use a Pandas DataFrame to construct a random sample of pets sub-divided by male and female:"
]
},
{
Expand All @@ -100,16 +111,28 @@
"\n",
"pets_sample = np.random.choice(pets, samples)\n",
"gender_sample = np.random.choice(genders, samples)\n",
"count = np.random.randint(1, 5, size=samples)\n",
"\n",
"bars = hv.Bars((pets_sample, gender_sample, np.ones(samples)), ['Pets', 'Gender']).aggregate(function=np.sum)\n",
"df = pd.DataFrame({'Pets': pets_sample, 'Gender': gender_sample, 'Count': count})\n",
"df.head(2)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"bars = hv.Bars(df, kdims=['Pets', 'Gender']).aggregate(function=np.sum)\n",
"\n",
"bars.opts(width=500)"
"bars.opts(width=800)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"\n",
"Just as before we can provide an explicit ordering by declaring the `Dimension.values`. Alternatively we can also make use of the `.sort` method, internally `Bars` will use topological sorting to ensure consistent ordering."
]
},
Expand Down Expand Up @@ -158,16 +181,29 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"For full documentation and the available style and plot options, use ``hv.help(hv.Bars).``"
"For full documentation and the available style and plot options, use ``hv.help(hv.Bars)``."
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"pygments_lexer": "ipython3"
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.5"
}
},
"nbformat": 4,
"nbformat_minor": 2
"nbformat_minor": 4
}

0 comments on commit fcbc6f5

Please sign in to comment.