Skip to content

Commit

Permalink
Add customization for the subplots example (#1371)
Browse files Browse the repository at this point in the history
Co-authored-by: Andrew <15331990+ahuang11@users.noreply.github.com>
  • Loading branch information
iuryt and ahuang11 committed Sep 13, 2024
1 parent 005ae0a commit 8dd07d8
Showing 1 changed file with 39 additions and 0 deletions.
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

0 comments on commit 8dd07d8

Please sign in to comment.