def test_builder_cross_backend_validation(self): Store.options(val=self.store_mpl, backend='matplotlib') Store.options(val=self.store_bokeh, backend='bokeh') Store.set_current_backend('bokeh') opts.Curve(line_dash='dotted') # Bokeh keyword opts.Curve(linewidth=10) # MPL keyword err = ( "In opts.Curve\(...\), keywords supplied are mixed across backends. " "Keyword\(s\) 'linewidth' are invalid for bokeh, " "'line_dash' are invalid for matplotlib") with self.assertRaisesRegexp(ValueError, err): opts.Curve(linewidth=10, line_dash='dotted') # Bokeh and MPL # Non-existent keyword across backends (bokeh active) err = ( "In opts.Curve\(...\), unexpected option 'foobar' for Curve type " "across all extensions. Similar options for current " "extension \('bokeh'\) are: \['toolbar'\].") with self.assertRaisesRegexp(ValueError, err): opts.Curve(foobar=3) # Non-existent keyword across backends (matplotlib active) Store.set_current_backend('matplotlib') err = ("In opts.Curve\(...\), unexpected option 'foobar' for Curve " "type across all extensions. No similar options found.") with self.assertRaisesRegexp(ValueError, err): opts.Curve(foobar=3)
def test_builder_cross_backend_validation(self): Store.options(val=self.store_mpl, backend='matplotlib') Store.options(val=self.store_bokeh, backend='bokeh') Store.set_current_backend('bokeh') opts.Curve(line_dash='dotted') # Bokeh keyword opts.Curve(linewidth=10) # MPL keyword err = ("In opts.Curve\(...\), keywords supplied are mixed across backends. " "Keyword\(s\) 'linewidth' are invalid for bokeh, " "'line_dash' are invalid for matplotlib") with self.assertRaisesRegexp(ValueError, err): opts.Curve(linewidth=10, line_dash='dotted') # Bokeh and MPL # Non-existent keyword across backends (bokeh active) err = ("In opts.Curve\(...\), unexpected option 'foobar' for Curve type " "across all extensions. Similar options for current " "extension \('bokeh'\) are: \['toolbar'\].") with self.assertRaisesRegexp(ValueError, err): opts.Curve(foobar=3) # Non-existent keyword across backends (matplotlib active) Store.set_current_backend('matplotlib') err = ("In opts.Curve\(...\), unexpected option 'foobar' for Curve " "type across all extensions. No similar options found.") with self.assertRaisesRegexp(ValueError, err): opts.Curve(foobar=3)
def setUp(self): if 'matplotlib' not in Store.renderers: raise SkipTest('Matplotlib backend not available.') self.store_copy = OptionTree(sorted(Store.options().items()), groups=Options._option_groups) self.backend = 'matplotlib' Store.set_current_backend(self.backend) super(TestOptsMethod, self).setUp()
def test_mpl_bokeh_mpl_via_builders_opts_method_implicit_backend(self): img = Image(np.random.rand(10,10)) Store.set_current_backend('matplotlib') mpl_opts = opts.Image(cmap='Blues') bokeh_opts = opts.Image(cmap='Purple', backend='bokeh') self.assertEqual('backend' not in mpl_opts.kwargs, True) self.assertEqual(bokeh_opts.kwargs['backend'], 'bokeh') img.opts(mpl_opts, bokeh_opts) mpl_lookup = Store.lookup_options('matplotlib', img, 'style').options self.assertEqual(mpl_lookup['cmap'], 'Blues') bokeh_lookup = Store.lookup_options('bokeh', img, 'style').options self.assertEqual(bokeh_lookup['cmap'], 'Purple') self.assert_output_options_group_empty(img)
def test_builder_backend_switch(self): Store.options(val=self.store_mpl, backend='matplotlib') Store.options(val=self.store_bokeh, backend='bokeh') Store.set_current_backend('bokeh') self.assertEqual(opts.Curve.__doc__.startswith('Curve('), True) docline = opts.Curve.__doc__.splitlines()[0] dockeys = eval(docline.replace('Curve', 'dict')) self.assertEqual('color' in dockeys, True) self.assertEqual('line_width' in dockeys, True) Store.set_current_backend('matplotlib') self.assertEqual(opts.Curve.__doc__.startswith('Curve('), True) docline = opts.Curve.__doc__.splitlines()[0] dockeys = eval(docline.replace('Curve', 'dict')) self.assertEqual('color' in dockeys, True) self.assertEqual('linewidth' in dockeys, True)
def test_mpl_bokeh_mpl_via_builders_opts_method_flat_literal_explicit_backend(self): img = Image(np.random.rand(10,10)) curve = Curve([1,2,3]) overlay = img * curve Store.set_current_backend('matplotlib') literal = {'Curve': dict(color='orange', backend='matplotlib'), 'Image': dict(cmap='jet', backend='bokeh') } styled = overlay.opts(literal) mpl_curve_lookup = Store.lookup_options('matplotlib', styled.Curve.I, 'style') self.assertEqual(mpl_curve_lookup.kwargs['color'], 'orange') mpl_img_lookup = Store.lookup_options('matplotlib', styled.Image.I, 'style') self.assertNotEqual(mpl_img_lookup.kwargs['cmap'], 'jet') bokeh_curve_lookup = Store.lookup_options('bokeh', styled.Curve.I, 'style') self.assertNotEqual(bokeh_curve_lookup.kwargs['color'], 'orange') bokeh_img_lookup = Store.lookup_options('bokeh', styled.Image.I, 'style') self.assertEqual(bokeh_img_lookup.kwargs['cmap'], 'jet')
from .util import load_tiff, from_xarray # noqa (API import) from .operation import project # noqa (API import) from . import data # noqa (API import) from . import operation # noqa (API import) from . import plotting # noqa (API import) from . import feature # noqa (API import) from . import tile_sources # noqa (API import) __version__ = str( param.version.Version(fpath=__file__, archive_commit="fcab9048", reponame="geoviews")) # Ensure opts utility is initialized with GeoViews elements if Store._options: Store.set_current_backend(Store.current_backend) # make pyct's example/data commands available if possible from functools import partial try: from pyct.cmd import copy_examples as _copy, fetch_data as _fetch, examples as _examples copy_examples = partial(_copy, 'geoviews') fetch_data = partial(_fetch, 'geoviews') examples = partial(_examples, 'geoviews') except ImportError: def _missing_cmd(*args, **kw): return ( "install pyct to enable this command (e.g. `conda install -c pyviz pyct`)" )
Contours, Graph, TriMesh, Nodes, EdgePaths, QuadMesh, VectorField, HexTiles, Labels) from .util import load_tiff, from_xarray # noqa (API import) from .operation import project # noqa (API import) from . import data # noqa (API import) from . import operation # noqa (API import) from . import plotting # noqa (API import) from . import feature # noqa (API import) from . import tile_sources # noqa (API import) __version__ = str(param.version.Version(fpath=__file__, archive_commit="cc70ac2d", reponame="geoviews")) # Ensure opts utility is initialized with GeoViews elements if Store._options: Store.set_current_backend(Store.current_backend) # make pyct's example/data commands available if possible from functools import partial try: from pyct.cmd import copy_examples as _copy, fetch_data as _fetch, examples as _examples copy_examples = partial(_copy, 'geoviews') fetch_data = partial(_fetch, 'geoviews') examples = partial(_examples, 'geoviews') except ImportError: def _missing_cmd(*args,**kw): return("install pyct to enable this command (e.g. `conda install -c pyviz pyct`)") _copy = _fetch = _examples = _missing_cmd def _err(): raise ValueError(_missing_cmd()) fetch_data = copy_examples = examples = _err del partial, _examples, _copy, _fetch
def setUp(self): self.store_copy = OptionTree(sorted(Store.options().items()), groups=['style', 'plot', 'norm']) self.backend = 'matplotlib' Store.set_current_backend(self.backend) super(TestOptsMethod, self).setUp()