-
-
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
Conversation
183fee5
to
4c1fb74
Compare
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.
Does it allow to style both the x and y axes at the same time? If not, how about using another approach (e.g. dict from axis to style, list of tuples)?
hvplot/converter.py
Outdated
grid : bool, str, 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'``, ``'dotdash'``, or ``'dashdot'`` |
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.
Are all these options supported by Matplotlib too? I recently looked into what line_dash
(bokeh) / linestyle
(matplotlib) supported and documented it there https://hvplot.holoviz.org/en/docs/latest/ref/api/manual/hvplot.hvPlot.line.html#line-dash.
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.
Are all these options supported by Matplotlib too? I recently looked into what line_dash (bokeh) / linestyle (matplotlib) supported and documented it there
Thanks, I totally neglected matplotlib (and plotly); I'll see if there's a way to convert it; if not just the dash or dotted should be sufficient.
Does it allow to style both the x and y axes at the same time? If not, how about using another approach (e.g. dict from axis to style, list of tuples)?
I personally think at that point, people should use plot.opts(gridstyle={...})
, else typing the {"line_dash": "dashed"}
would be tedious. What do you think?
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.
Thanks, I totally neglected matplotlib (and plotly); I'll see if there's a way to convert it; if not just the dash or dotted should be sufficient.
You can ignore Plotly.
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.
Interestingly, holoviews mpl does not support gridstyle so I guess I need to implement it in hv first...
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.
Ugh :/ Had a discussion recently on Discord where I said HoloViews isn't a plotting library. That's exactly what I meant :D
I just realized something. When it comes to plot styling options, hvPlot usually acts as a pass-through. One advantage of that is that the keys and their allowed values are common between hvPlot and HoloViews (so it's easier for users to go from one to the other). One disadvantage is that the keys and their values are backend-dependent. As a result, we haven't attempted to build a "unified styling API" in hvPlot, that would work for all the supported backends.
It looks like this is where we are heading in this PR with e.g. grid="x-dashed"
. Can I have your thoughts on that?
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.
Interestingly, holoviews mpl does not support gridstyle
holoviz/holoviews#6700
It looks like this is where we are heading in this PR with e.g. grid="x-dashed". Can I have your thoughts on that?.
I actually just added a clause for dict support, so all of grid='x'
, 'grid='x-dashed'
, grid={'grid_line_color': 'red'}
works.
hvPlot usually acts as a pass-through
To me, hvplot is not only a pass-through--(me being a PM for a second) it's a stress-free, direct plotting experience (at least for me), without having to deal with complex dict structures. Every time I have to use legend_opts or gridstyle, I have to pause and remember the valid key value pairs, which is why I like having a string like x-dashed
or x.dashed
or xdashed
.
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.
As a result, we haven't attempted to build a "unified styling API" in hvPlot, that would work for all the supported backends.
Oh and I also don't fully understand the backend_compat, so I dumped directly in the function, but I imagine there could be a better place if you can help me understand the flow of converter.py, maybe in _process_style
?
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.
Yeah I'm not sure where to do that to be honest. I think you're pretty much introducing a new pattern with a unified plot API for multiple backends. Probably not _process_style
as gridstyle
is a plot option in HoloViews. But having that in the __init__.py
doesn't feel right either?
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.
I think we need to clearly answer:
- Is styling the grid a common enough thing to expose it in the API?
- If so, is the suggested str config API covering a subset that overlaps with the most common usage patterns?
- Is the suggested str config API easy to discover and remember? (if not, there's no need for it and we can just rely on good documentation)
Imo:
- Yes
- I'm not really sure as there are many ways to style a grid (line style, color, width, alpha; full or only x or only x; + minor grids and their styling). I tend to think that setting the line style ranks high (as an easy way to make the grid less prominent, instead of fiddling with color/alpha/width). @ahuang11 shouldn't
grid
also simply allow'dotted'
/etc. to style the whole grid? - I think it's OK? I'm not sure why
-
was chosen (x-dashed
) instead of other characters but have no strong opinion about it. I also prefer the word-style (dashed
over--
).
I think we also need to define the scope of the str config API upfront, in case users come and ask for it to be extended (width, color, alpha, etc.).
"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 comment
The 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": "markdown", | ||
"id": "59315b89", | ||
"metadata": {}, | ||
"source": [ |
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.
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 comment
The reason will be displayed to describe this comment to others. Learn more.
Why lstrip('.').lstrip('_')
?
hvplot/converter.py
Outdated
grid : bool, str, 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'``, ``'dotdash'``, or ``'dashdot'`` |
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.
Yeah I'm not sure where to do that to be honest. I think you're pretty much introducing a new pattern with a unified plot API for multiple backends. Probably not _process_style
as gridstyle
is a plot option in HoloViews. But having that in the __init__.py
doesn't feel right either?
Enables:
"""
To show grid only on the x-axis, use
grid='x'
. To show grid only on the y-axis, usegrid='y'
. To change the grid line style, suffix with'dashed'
,'dotted'
,'dotdash'
, or'dashdot'
, e.g.grid='x-dashed'
."""
Closes: #1440