Skip to content

Commit

Permalink
Minor tweaks relating to options (#3502)
Browse files Browse the repository at this point in the history
  • Loading branch information
jlstevens authored and philippjfr committed Feb 22, 2019
1 parent 9246f47 commit 3471ff8
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
11 changes: 6 additions & 5 deletions examples/getting_started/2-Customization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@
"source": [
"# Switching to matplotlib\n",
"\n",
"Now let's customize our `layout` with options appropriate for the [Matplotlib](http://matplotlib.org) renderer, by supplying the `backend='matplotlib'` argument to the `.opts` method:"
"Now let's customize our `layout` with options appropriate for the [Matplotlib](http://matplotlib.org) renderer, by supplying options associated with the matplotlib backend to the `.opts` method:"
]
},
{
Expand All @@ -250,17 +250,18 @@
"outputs": [],
"source": [
"layout = layout.opts(\n",
" opts.Curve( aspect=6, xaxis=None, color='blue', linewidth=2, show_grid=False, linestyle='dashed'),\n",
" opts.Spikes(aspect=6, yaxis='bare', color='red', linewidth=0.25),\n",
" opts.Layout(sublabel_format='', vspace=0.1, fig_size=200), backend='matplotlib')\n",
" opts.Curve( aspect=6, xaxis=None, color='blue', linewidth=2, show_grid=False, \n",
" linestyle='dashed', backend='matplotlib'),\n",
" opts.Spikes(aspect=6, yaxis='bare', color='red', linewidth=0.25, backend='matplotlib'),\n",
" opts.Layout(sublabel_format='', vspace=0.1, fig_size=200, backend='matplotlib'))\n",
"layout"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The plot is still rendered with bokeh as we haven't switched to the matplotlib backend just yet (although matplotlib support was was loaded by `hv.extension` at the start of this notebook). The above code sets the options appropriate to matplotlib without immediately making use of them and naturally, a few changes needed to be made:\n",
"These options are now associated with matplotlib (due to `backend='matplotlib'`) even though the plot is still rendered with bokeh as we haven't switched to the matplotlib backend just yet (although matplotlib support was was loaded by `hv.extension` at the start of this notebook). The above code sets the options appropriate to matplotlib without immediately making use of them and naturally, a few changes needed to be made:\n",
"\n",
"* Some of the options are different because of differences in how the plotting backends work. For instance, matplotlib uses ``aspect`` instead of setting ``width`` and ``height``. In some cases, but not all, HoloViews can smooth over such differences in the *plotting* options to make it simpler to switch backends.\n",
"* The Bokeh hover tool is not supported by the matplotlib backend, as you might expect, nor are there any other interactive controls, because the Matplotlib backend generates static PNG or SVG images.\n",
Expand Down
6 changes: 3 additions & 3 deletions examples/user_guide/03-Applying_Customization.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@
"outputs": [],
"source": [
"path = path.opts(\n",
" opts.Path(linewidth=3, color='blue'), backend='matplotlib')\n",
" opts.Path(linewidth=3, color='blue', backend='matplotlib'))\n",
"path"
]
},
Expand All @@ -446,7 +446,7 @@
"source": [
"Passing `hv.output` an object will apply the specified settings only for the subsequent display. If you were to view `path` now in the usual way, you would see that it is still being displayed with Bokeh with purple dotted lines.\n",
"\n",
"One thing to note is that when we set the options with `backend='matplotlib'`, the active plotting extension was Bokeh. This means that `opts.Path` will tab complete *bokeh* keywords, and not the matplotlib ones that were specified. However, as matplotlib was loaded with `hv.extension`, these matplotlib keywords are considered valid regardless. In practice you will want to set the backend appropriately before building your options settings, to ensure that you get the most appropriate tab completion."
"One thing to note is that when we set the options with `backend='matplotlib'`, the active plotting extension was Bokeh. This means that `opts.Path` will tab complete *bokeh* keywords, and not the matplotlib ones that were specified. In practice you will want to set the backend appropriately before building your options settings, to ensure that you get the most appropriate tab completion."
]
},
{
Expand Down Expand Up @@ -736,7 +736,7 @@
"full_literal_spec = {\n",
" 'Curve': {'style':dict(color='orange')}, \n",
" 'Curve.Sinusoid': {'style':dict(color='grey')}, \n",
" 'Curve.Sinusoid.Squared ': {'style':dict(color='black'),\n",
" 'Curve.Sinusoid.Squared': {'style':dict(color='black'),\n",
" 'plot':dict(interpolation='steps-mid')}}\n",
"curves.opts(full_literal_spec)"
]
Expand Down
12 changes: 5 additions & 7 deletions holoviews/core/options.py
Original file line number Diff line number Diff line change
Expand Up @@ -1452,7 +1452,6 @@ def register(cls, associations, backend, style_aliases={}):
Register the supplied dictionary of associations between
elements and plotting classes to the specified backend.
"""
from .overlay import CompositeOverlay
if backend not in cls.registry:
cls.registry[backend] = {}
cls.registry[backend].update(associations)
Expand All @@ -1477,12 +1476,11 @@ def register(cls, associations, backend, style_aliases={}):
style_opts = Keywords(style_opts, target=view_class.__name__)

opt_groups = {'plot': Options(allowed_keywords=plot_opts),
'output': Options(allowed_keywords=Options._output_allowed_kws)}
if not isinstance(view_class, CompositeOverlay) or hasattr(plot, 'style_opts'):
opt_groups.update({'style': Options(allowed_keywords=style_opts),
'norm': Options(framewise=False, axiswise=False,
allowed_keywords=['framewise',
'axiswise'])})
'output': Options(allowed_keywords=Options._output_allowed_kws),
'style': Options(allowed_keywords=style_opts),
'norm': Options(framewise=False, axiswise=False,
allowed_keywords=['framewise',
'axiswise'])}

name = view_class.__name__
cls._options[backend][name] = opt_groups
Expand Down
2 changes: 1 addition & 1 deletion holoviews/util/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ def _group_kwargs_to_options(cls, obj, kwargs):
','.join(repr(k) for k in kwargs.keys()))

# Check whether the user is specifying targets (such as 'Image.Foo')
targets = [all(k[0].isupper() for k in grp.keys()) for grp in kwargs.values()]
targets = [grp and all(k[0].isupper() for k in grp) for grp in kwargs.values()]
if any(targets) and not all(targets):
raise Exception("Cannot mix target specification keys such as 'Image' with non-target keywords.")
elif not any(targets):
Expand Down

0 comments on commit 3471ff8

Please sign in to comment.