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

Fix typo in MATPLOTLIB_TRANSFORMS #1380

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
2 changes: 1 addition & 1 deletion hvplot/backend_transforms.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ def _transfer_opts_cur_backend(element):
'style': {
'bar_width': UNSET,
'size': lambda k, v: ('s', v),
'fill_color': lambda k, v: ('facecolor', v),
'fill_color': lambda k, v: ('facecolors', v),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please demonstrate with an example the effect of this change? I think that HoloViews accepts either facecolor or facecolors as a style option for the Matplotlib backend, depending on the element type (e.g. https://github.com/holoviz/holoviews/blob/e6024ccc0c04e1b8678b76467491cf85c68a9aee/holoviews/plotting/mpl/chart.py#L215 and https://github.com/holoviz/holoviews/blob/e6024ccc0c04e1b8678b76467491cf85c68a9aee/holoviews/plotting/mpl/chart.py#L589). So we need to make sure what we map to exactly. And maybe, given the current mapping structure, it might not always be possible to map from a bokeh option to a mpl one if there are this kind of differences.

This comment was marked as outdated.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me update the example based on #1378:

import hvplot.xarray
import holoviews
import xarray
from hvplot.backend_transforms import MATPLOTLIB_TRANSFORMS

hvplot.extension("bokeh", "matplotlib", compatibility="bokeh")

data = xarray.DataArray([0, 1, 2])
data.name="Needs a name"

hvplot.output(backend="matplotlib")

## Uncomment to see it fixed
# MATPLOTLIB_TRANSFORMS["style"]["fill_color"] = lambda k, v: ('facecolors', v)

overlay = holoviews.Overlay()
curve_line = data.hvplot(kind="line")
overlay *= curve_line
curve_scatter = data.hvplot(kind="scatter", fill_color="red", size=5000)
overlay *= curve_scatter
overlay

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To illustrate what I mean with the complexity to map from a backend to another.

global_option_tree = hv.Store.options(backend='bokeh')
fill_color = []
for element, option_tree in global_option_tree.items():
    element = element[0]
    style_opts = option_tree.groups['style']
    allowed_styles = style_opts.allowed_keywords
    if 'fill_color' in allowed_styles:
        fill_color.append(str(element))

print('Bokeh')
print(f'fill_color: {sorted(fill_color)}')
print()

global_option_tree = hv.Store.options(backend='matplotlib')
facecolors = []
facecolor = []
for element, option_tree in global_option_tree.items():
    element = element[0]
    style_opts = option_tree.groups['style']
    allowed_styles = style_opts.allowed_keywords
    if 'facecolor' in allowed_styles:
        facecolor.append(str(element))
    if 'facecolors' in allowed_styles:
        facecolors.append(str(element))


print('Matplotlib')
print(f'facecolor: {sorted(facecolor)}')
print(f'facecolors: {sorted(facecolors)}')
Bokeh
fill_color: ['Area', 'Bars', 'Bivariate', 'Distribution', 'HSpan', 'HSpans', 'HeatMap', 'HexTiles', 'Histogram', 'Nodes', 'Points', 'Polygons', 'QuadMesh', 'Rectangles', 'Scatter', 'Spread', 'VSpan', 'VSpans']

Matplotlib
facecolor: ['Area', 'Bars', 'Bivariate', 'Distribution', 'HLines', 'HSpan', 'HSpans', 'Histogram', 'Polygons', 'Rectangles', 'Spread', 'VLines', 'VSpan', 'VSpans']
facecolors: ['Nodes', 'Points', 'Scatter', 'Scatter3D', 'Surface', 'VectorField', 'Violin']

So this is likely not a type, and needs more investigation to see whether changing it as suggested in the PR is worth it (i.e. another class of users happy with the current behavior may be unhappy with the new one).

'fill_alpha': UNSET,
'line_alpha': UNSET,
'line_cap': lambda k, v: ('capstyle', _line_cap_bk_mpl_mapping.get(v, UNSET)),
Expand Down