-
-
Notifications
You must be signed in to change notification settings - Fork 113
Add gridstyle #1680
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
base: main
Are you sure you want to change the base?
Add gridstyle #1680
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -311,6 +311,54 @@ | |
| "plot2 = df.hvplot(group_label=\"Company\", grid=True, width=400, title=\"grid=True\")\n", | ||
| "(plot1 + plot2).cols(1)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "56cdf3e2", | ||
| "metadata": {}, | ||
| "source": [ | ||
| "To show grid only on the x-axis, use ``grid='x'``. To show grid only on the y-axis, use ``grid='y'``. To change the grid line style, suffix with ``'dashed'``, ``'dotted'``, or ``'dashdot'``, e.g. ``grid='x-dashed'``." | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "7e38dee4", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import hvplot.pandas # noqa\n", | ||
| "\n", | ||
| "df = hvplot.sampledata.stocks(\"pandas\", engine_kwargs={\"index_col\" : \"date\"})\n", | ||
| "\n", | ||
| "plot1 = df.hvplot(group_label=\"Company\", grid='x', width=400, title=\"grid='x'\")\n", | ||
| "plot2 = df.hvplot(group_label=\"Company\", grid='y-dashed', width=400, title=\"grid='y-dashed'\")\n", | ||
| "(plot1 + plot2).cols(1)" | ||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "markdown", | ||
| "id": "59315b89", | ||
| "metadata": {}, | ||
| "source": [ | ||
| " A dictionary of grid style options may also be supplied, e.g. for bokeh, ``{'grid_line_color': 'red', 'grid_line_alpha': 0.5}``." | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you update one of the examples to make it a bit more advanced? I'm thinking that one with minor grid lines would be pretty nice. |
||
| ] | ||
| }, | ||
| { | ||
| "cell_type": "code", | ||
| "execution_count": null, | ||
| "id": "d3b095ba", | ||
| "metadata": {}, | ||
| "outputs": [], | ||
| "source": [ | ||
| "import hvplot.pandas # noqa\n", | ||
| "\n", | ||
| "df = hvplot.sampledata.stocks(\"pandas\", engine_kwargs={\"index_col\" : \"date\"})\n", | ||
| "\n", | ||
| "plot1 = df.hvplot(group_label=\"Company\", grid={'grid_line_color': 'red', 'grid_line_alpha': 0.5}, width=400, title=\"grid=dict\")\n", | ||
| "plot2 = df.hvplot(group_label=\"Company\", grid={'xgrid_line_color': 'green', 'xgrid_line_alpha': 0.5}, width=400, title=\"grid=dict (x-axis only)\")\n", | ||
| "(plot1 + plot2).cols(1)" | ||
| ] | ||
| } | ||
| ], | ||
| "metadata": { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -475,8 +475,13 @@ class HoloViewsConverter: | |
| fontsize : number or dict or None, default=None | ||
| Set title, label and legend text to the same fontsize. Finer control | ||
| by using a dict: ``{'title': '15pt', 'ylabel': '5px', 'ticks': 20}``. | ||
| grid : bool or None, default=None | ||
| Whether to show a grid. | ||
| grid : bool, str, dict, or None, default=None | ||
| Whether to show a grid. If True, shows grid on both axes. | ||
| If ``'x'`` or ``'y'``, shows grid only on the specified axis. | ||
| Suffix with ``'dashed'``, ``'dotted'``, or ``'dashdot'`` | ||
| to change the grid line style, e.g. ``'x-dashed'``. | ||
| A dictionary of grid style options may also be supplied, e.g. for bokeh, | ||
| ``{'grid_line_color': 'red', 'grid_line_alpha': 0.5}``. | ||
|
|
||
| Resampling Options | ||
| ------------------ | ||
|
|
@@ -1059,7 +1064,28 @@ def __init__( | |
| plot_opts['logy'] = logy | ||
|
|
||
| if grid is not None: | ||
| plot_opts['show_grid'] = grid | ||
| if isinstance(grid, str): | ||
| gridstyle = {} | ||
| axis = grid[0] | ||
| other_axis = 'x' if axis == 'y' else 'y' | ||
| if len(grid) > 1: | ||
| line_dash = grid[1:].lstrip('-').lstrip('.').lstrip('_') | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why |
||
| line_dash_key = ( | ||
| f'{axis}grid_line_dash' | ||
| if self._backend_compat == 'bokeh' | ||
| else f'{axis}grid_linestyle' | ||
| ) | ||
| gridstyle[line_dash_key] = line_dash | ||
| line_alpha_key = ( | ||
| f'{other_axis}grid_line_alpha' | ||
| if self._backend_compat == 'bokeh' | ||
| else f'{other_axis}grid_alpha' | ||
| ) | ||
| gridstyle[line_alpha_key] = 0 | ||
| plot_opts['gridstyle'] = gridstyle | ||
| elif isinstance(grid, dict): | ||
| plot_opts['gridstyle'] = grid | ||
| plot_opts['show_grid'] = bool(grid) | ||
|
|
||
| if legend is not None: | ||
| plot_opts['show_legend'] = bool(legend) | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you link to Bokeh's docs? So users have an easy way to check all the options they can set.