Skip to content
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
158 changes: 158 additions & 0 deletions doc/ref/plotting_options/grid_legend.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
{
"cells": [
{
"cell_type": "markdown",
"id": "48c92d94-f7f0-4d07-b96b-4eeae31df55f",
"metadata": {},
"source": [
"# Grid And Legend Options\n",
"\n",
"```{eval-rst}\n",
".. plotting-options-table:: Grid And Legend Options\n",
"```"
]
},
{
"cell_type": "markdown",
"id": "80d84d3f-9354-4e6a-a170-708bf5601aa5",
"metadata": {},
"source": [
"(option-colorbar)=\n",
"## `colorbar`\n",
"\n",
"Toggles the display of a colorbar alongside your plot. By default, some plots (e.g. heatmap, image, contour) show a colorbar when mapping a numerical dimension to color. Setting `colorbar=False` will hide it, while `colorbar=True` forces it on even for rasterized or non-default cases."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "69fbe598-529c-446b-9f7a-12ef12f061c2",
"metadata": {},
"outputs": [],
"source": [
"import hvplot.xarray # noqa\n",
"import hvsampledata\n",
"\n",
"df = hvsampledata.air_temperature(\"xarray\").sel(time=\"2014-02-25 12:00\")\n",
"plot1 = df.hvplot.image(title=\"Default: colorbar=True\", width=350)\n",
"plot2 = df.hvplot.image(title=\"colorbar=False\", width=350, colorbar=False)\n",
"\n",
"plot1 + plot2"
]
},
{
"cell_type": "markdown",
"id": "09881e22-1836-4c68-b3e6-9e19eb6867fc",
"metadata": {},
"source": [
"(option-grid)=\n",
"## `grid`\n",
"\n",
"Turns grid lines on or off behind your data. By default grids are disabled; use `grid=True` to draw horizontal and vertical lines at each major tick mark."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6e143587-9bce-4c00-8296-7db329ed3723",
"metadata": {},
"outputs": [],
"source": [
"import hvplot.pandas # noqa\n",
"import hvsampledata\n",
"\n",
"df = hvsampledata.stocks(\"pandas\", engine_kwargs={\"index_col\" : \"date\"})\n",
"\n",
"plot1 = df.hvplot(group_label=\"Company\", width=400, title=\"Default: grid=False\")\n",
"plot2 = df.hvplot(group_label=\"Company\", grid=True, width=400, title=\"grid=True\")\n",
"\n",
"plot1 + plot2"
]
},
{
"cell_type": "markdown",
"id": "7c6cc816-2cc3-4af6-94a5-ed04b3bfe3ce",
"metadata": {},
"source": [
"(option-legend)=\n",
"## `legend`\n",
"\n",
"Controls whether and where the legend appears. \n",
"- Set `legend=False` to hide the legend. \n",
"- Use `legend=True` (or `legend='right'`) to show it in the default position. \n",
"- Specify one of the cardinal positions `'top'`, `'bottom'`, `'left'`, or `'right'`. \n",
"- Choose a corner placement with `'top_left'`, `'top_right'`, `'bottom_left'`, or `'bottom_right'`."
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "6d07e0f0-8cde-4e2f-9ab9-47dc06be11b6",
"metadata": {},
"outputs": [],
"source": [
"import hvplot.pandas # noqa\n",
"import hvsampledata\n",
"\n",
"df = hvsampledata.penguins(\"pandas\")\n",
"\n",
"opts = dict(\n",
" x='flipper_length_mm',\n",
" y='body_mass_g',\n",
" by='species',\n",
" frame_width=200,\n",
" aspect='square'\n",
")\n",
"\n",
"plot1 = df.hvplot.scatter(title=\"Default: legend=right\", **opts)\n",
"plot2 = df.hvplot.scatter(legend='left', title=\"legend=left\", **opts)\n",
"plot3 = df.hvplot.scatter(legend='top', title=\"legend=top\", **opts)\n",
"plot4 = df.hvplot.scatter(legend='bottom', title=\"legend=bottom\", **opts)\n",
"plot5 = df.hvplot.scatter(legend='bottom_left', title=\"legend=bottom_left\", **opts)\n",
"plot6 = df.hvplot.scatter(legend='bottom_right', title=\"legend=bottom_right\", **opts)\n",
"plot7 = df.hvplot.scatter(legend='top_left', title=\"legend=top_left\", **opts)\n",
"plot8 = df.hvplot.scatter(legend='top_right', title=\"legend=top_right\", **opts)\n",
"\n",
"plot1 + plot2"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "48367226-cce5-4675-9408-f4ca2f586236",
"metadata": {},
"outputs": [],
"source": [
"plot3 + plot4"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "964954e3-acc4-419c-96af-5e9409c7d2f2",
"metadata": {},
"outputs": [],
"source": [
"plot5 + plot6"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "baa84773-9626-43a1-b981-e7c81614d1c5",
"metadata": {},
"outputs": [],
"source": [
"plot7 + plot8"
]
}
],
"metadata": {
"language_info": {
"name": "python",
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
3 changes: 3 additions & 0 deletions doc/ref/plotting_options/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ Options for setting the grid or legend of plots as well as colorbar options:
.. plotting-options-table:: Grid And Legend Options
```

See [this page](./grid_legend) for more information on these options.

(plotting-options-styling)=
## Styling Options

Expand Down Expand Up @@ -105,5 +107,6 @@ Options for handling live data streams:

All Options <self>
Data Options <data>
Grid And Legend Options <grid_legend>
Size And Layout Options <size_layout>
```
Loading