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 customization for the subplots example #1371

Merged
merged 5 commits into from
Sep 13, 2024
Merged
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
39 changes: 39 additions & 0 deletions doc/user_guide/Plotting_with_Matplotlib.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -635,6 +635,45 @@
" crime.hvplot.table(['Year', 'Population', 'Violent Crime rate'], width=420))"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"We can further enhance the plot by using a `step`s chart instead of a `bar` chart to avoid visual clutter and better represent the continuous nature of time series data. Additionally, we can display a table summarizing decade-averaged statistics to provide a quick overview of the data. The `sublabel` format and size can be customized, and if not needed, can be removed by setting `sublabel_format=\"\"` in [opts](https://holoviews.org/user_guide/Applying_Customizations.html)."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"tabledata = (\n",
" crime.assign(\n",
" **{\n",
" \"Decade\": (crime.Year // 10) * 10, # Calculate decade for each year\n",
" \"Population [mi]\": crime.Population / 1e6, # Population in millions\n",
" }\n",
" )\n",
" .groupby(\"Decade\") # Group data by decade\n",
" .mean() # Calculate mean values for each decade group\n",
" [[\"Population [mi]\", \"Violent Crime rate\"]] # Select desired columns\n",
" .astype(\"int\") # Convert selected columns to integers\n",
")"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"(\n",
" crime.hvplot.step(x='Year', y='Violent Crime rate', rot=90, width=550)+\n",
" tabledata.hvplot.table(['Decade', 'Population [mi]', 'Violent Crime rate'], width=15, height=10)\n",
").opts(sublabel_format=\"{alpha})\", sublabel_size=14)"
]
},
{
"cell_type": "markdown",
"metadata": {},
Expand Down
Loading