예제 #1
0
 def test_symmetric_with_big_img_and_check_symmetric_max_calculates_symmetric(
         self):
     plot = self.big_img.hvplot.image(check_symmetric_max=int(1e7))
     plot_opts = Store.lookup_options('bokeh', plot, 'plot')
     self.assertEqual(plot_opts.kwargs.get('symmetric'), True)
     style_opts = Store.lookup_options('bokeh', plot, 'style')
     self.assertEqual(style_opts.kwargs['cmap'], 'coolwarm')
예제 #2
0
    def test_custom_magic_to_default_inheritance(self):
        """
        Checks customs inheritance backs off to default tree correctly
        simulating the %%opts cell magic.
        """
        if 'matplotlib' not in Store.renderers:
            raise SkipTest("Custom magic inheritance test requires matplotlib")
        options = self.initialize_option_tree()
        options.Image.A.B = Options('style', alpha=0.2)

        obj = Image(np.random.rand(10, 10), group='A', label='B')

        # Before customizing...
        expected_obj =  {'alpha': 0.2, 'cmap': 'hot', 'interpolation': 'nearest'}
        obj_lookup = Store.lookup_options('matplotlib', obj, 'style')
        self.assertEqual(obj_lookup.kwargs, expected_obj)

        custom_tree = {0: OptionTree(groups=['plot', 'style', 'norm'],
                                     style={'Image' : dict(clims=(0, 0.5))})}
        Store._custom_options['matplotlib'] = custom_tree
        obj.id = 0 # Manually set the id to point to the tree above

        # Customize this particular object
        expected_custom_obj =  dict(clims=(0,0.5), **expected_obj)
        custom_obj_lookup = Store.lookup_options('matplotlib', obj, 'style')
        self.assertEqual(custom_obj_lookup.kwargs, expected_custom_obj)
예제 #3
0
 def test_mpl_bokeh_offset_mpl(self):
     img = Image(np.random.rand(10,10))
     # Use blue in matplotlib
     Store.current_backend = 'matplotlib'
     StoreOptions.set_options(img, style={'Image':{'cmap':'Blues'}})
     mpl_opts = Store.lookup_options('matplotlib', img, 'style').options
     self.assertEqual(mpl_opts, {'cmap':'Blues'})
     # Switch to bokeh and style a random object...
     Store.current_backend = 'bokeh'
     img2 = Image(np.random.rand(10,10))
     StoreOptions.set_options(img2, style={'Image':{'cmap':'Reds'}})
     img2_opts = Store.lookup_options('bokeh', img2, 'style').options
     self.assertEqual(img2_opts, {'cmap':'Reds'})
     # Use purple in bokeh on the object...
     StoreOptions.set_options(img, style={'Image':{'cmap':'Purple'}})
     bokeh_opts = Store.lookup_options('bokeh', img, 'style').options
     self.assertEqual(bokeh_opts, {'cmap':'Purple'})
     # Check it is still blue in matplotlib...
     Store.current_backend = 'matplotlib'
     mpl_opts = Store.lookup_options('matplotlib', img, 'style').options
     self.assertEqual(mpl_opts, {'cmap':'Blues'})
     # And purple in bokeh..
     Store.current_backend = 'bokeh'
     bokeh_opts = Store.lookup_options('bokeh', img, 'style').options
     self.assertEqual(bokeh_opts, {'cmap':'Purple'})
     return img
예제 #4
0
    def test_custom_magic_to_default_inheritance(self):
        """
        Checks customs inheritance backs off to default tree correctly
        simulating the %%opts cell magic.
        """
        if 'matplotlib' not in Store.renderers:
            raise SkipTest("Custom magic inheritance test requires matplotlib")
        options = self.initialize_option_tree()
        options.Image.A.B = Options('style', alpha=0.2)

        obj = Image(np.random.rand(10, 10), group='A', label='B')

        # Before customizing...
        expected_obj = {
            'alpha': 0.2,
            'cmap': 'hot',
            'interpolation': 'nearest'
        }
        obj_lookup = Store.lookup_options('matplotlib', obj, 'style')
        self.assertEqual(obj_lookup.kwargs, expected_obj)

        custom_tree = {
            0:
            OptionTree(groups=Options._option_groups,
                       style={'Image': dict(clims=(0, 0.5))})
        }
        Store._custom_options['matplotlib'] = custom_tree
        obj.id = 0  # Manually set the id to point to the tree above

        # Customize this particular object
        expected_custom_obj = dict(clims=(0, 0.5), **expected_obj)
        custom_obj_lookup = Store.lookup_options('matplotlib', obj, 'style')
        self.assertEqual(custom_obj_lookup.kwargs, expected_custom_obj)
예제 #5
0
 def test_symmetric_with_big_img_sets_symmetric_to_false_without_calculating(
         self):
     plot = self.big_img.hvplot.image()
     plot_opts = Store.lookup_options('bokeh', plot, 'plot')
     self.assertEqual(plot_opts.kwargs.get('symmetric'), False)
     style_opts = Store.lookup_options('bokeh', plot, 'style')
     self.assertEqual(style_opts.kwargs['cmap'], 'kbc_r')
예제 #6
0
 def test_mpl_bokeh_offset_mpl(self):
     img = Image(np.random.rand(10, 10))
     # Use blue in matplotlib
     Store.current_backend = 'matplotlib'
     StoreOptions.set_options(img, style={'Image': {'cmap': 'Blues'}})
     mpl_opts = Store.lookup_options('matplotlib', img, 'style').options
     self.assertEqual(mpl_opts, {'cmap': 'Blues'})
     # Switch to bokeh and style a random object...
     Store.current_backend = 'bokeh'
     img2 = Image(np.random.rand(10, 10))
     StoreOptions.set_options(img2, style={'Image': {'cmap': 'Reds'}})
     img2_opts = Store.lookup_options('bokeh', img2, 'style').options
     self.assertEqual(img2_opts, {'cmap': 'Reds'})
     # Use purple in bokeh on the object...
     StoreOptions.set_options(img, style={'Image': {'cmap': 'Purple'}})
     bokeh_opts = Store.lookup_options('bokeh', img, 'style').options
     self.assertEqual(bokeh_opts, {'cmap': 'Purple'})
     # Check it is still blue in matplotlib...
     Store.current_backend = 'matplotlib'
     mpl_opts = Store.lookup_options('matplotlib', img, 'style').options
     self.assertEqual(mpl_opts, {'cmap': 'Blues'})
     # And purple in bokeh..
     Store.current_backend = 'bokeh'
     bokeh_opts = Store.lookup_options('bokeh', img, 'style').options
     self.assertEqual(bokeh_opts, {'cmap': 'Purple'})
     return img
예제 #7
0
 def test_style_transfer(self):
     hist = self.hist.opts(style={'style1': 'style_child'})
     hist2 = self.hist.opts()
     opts = Store.lookup_options('matplotlib', hist2, 'style').kwargs
     self.assertEqual(opts, {'style1': 'style1', 'style2': 'style2'})
     Store.transfer_options(hist, hist2, 'matplotlib')
     opts = Store.lookup_options('matplotlib', hist2, 'style').kwargs
     self.assertEqual(opts, {'style1': 'style_child', 'style2': 'style2'})
예제 #8
0
 def test_style_transfer(self):
     hist = self.hist.opts(style={'style1':'style_child'})
     hist2 = self.hist.opts()
     opts = Store.lookup_options('matplotlib', hist2, 'style').kwargs
     self.assertEqual(opts, {'style1': 'style1', 'style2': 'style2'})
     Store.transfer_options(hist, hist2, 'matplotlib')
     opts = Store.lookup_options('matplotlib', hist2, 'style').kwargs
     self.assertEqual(opts, {'style1': 'style_child', 'style2': 'style2'})
예제 #9
0
 def test_style_inheritance_addition(self):
     "Adding an element"
     hist2 = self.hist(style={"style3": "style3"})
     self.assertEqual(
         Store.lookup_options(hist2, "style").options, dict(style1="style1", style2="style2", style3="style3")
     )
     # Check plot options works as expected
     self.assertEqual(Store.lookup_options(hist2, "plot").options, self.default_plot)
예제 #10
0
 def test_mpl_bokeh_mpl_via_dict_backend_keyword(self):
     curve = Curve([1,2,3])
     styled_mpl = curve.opts({'Curve': dict(color='red')}, backend='matplotlib')
     styled = styled_mpl.opts({'Curve': dict(color='green')}, backend='bokeh')
     mpl_lookup = Store.lookup_options('matplotlib', styled, 'style')
     self.assertEqual(mpl_lookup.kwargs['color'], 'red')
     bokeh_lookup = Store.lookup_options('bokeh', styled, 'style')
     self.assertEqual(bokeh_lookup.kwargs['color'], 'green')
예제 #11
0
 def test_symmetric_dataframe(self):
     import pandas as pd
     df = pd.DataFrame([[1, 2, -1], [3, 4, 0], [5, 6, 1]],
                       columns=['x', 'y', 'number'])
     plot = df.hvplot.scatter('x', 'y', c='number')
     plot_opts = Store.lookup_options('bokeh', plot, 'plot')
     self.assertEqual(plot_opts.kwargs['symmetric'], True)
     style_opts = Store.lookup_options('bokeh', plot, 'style')
     self.assertEqual(style_opts.kwargs['cmap'], 'coolwarm')
예제 #12
0
 def test_if_clim_is_set_symmetric_is_not_deduced(self):
     plot = self.symmetric_df.hvplot.scatter('x',
                                             'y',
                                             c='number',
                                             clim=(-1, 1))
     plot_opts = Store.lookup_options('bokeh', plot, 'plot')
     self.assertEqual(plot_opts.kwargs.get('symmetric'), None)
     style_opts = Store.lookup_options('bokeh', plot, 'style')
     self.assertEqual(style_opts.kwargs['cmap'], 'kbc_r')
예제 #13
0
 def test_symmetric_from_opts_does_not_deduce(self):
     plot = self.symmetric_df.hvplot.scatter('x',
                                             'y',
                                             c='number',
                                             symmetric=False)
     plot_opts = Store.lookup_options('bokeh', plot, 'plot')
     self.assertEqual(plot_opts.kwargs['symmetric'], False)
     style_opts = Store.lookup_options('bokeh', plot, 'style')
     self.assertEqual(style_opts.kwargs['cmap'], 'kbc_r')
예제 #14
0
 def test_define_customize_method(self):
     holoplot = HoloPlot(self.df, {'scatter': {'width': 42, 'height': 42}})
     custom_scatter = holoplot.scatter(y='y')
     curve = holoplot.line(y='y')
     custom_opts = Store.lookup_options('bokeh', custom_scatter, 'plot')
     opts = Store.lookup_options('bokeh', curve, 'plot')
     self.assertEqual(custom_opts.options.get('width'), 42)
     self.assertEqual(custom_opts.options.get('height'), 42)
     self.assertNotEqual(opts.options.get('width'), 42)
     self.assertNotEqual(opts.options.get('height'), 42)
예제 #15
0
 def test_define_custom_method(self):
     hvplot = hvPlotTabular(self.df, {'custom_scatter': {'width': 42, 'height': 42}})
     custom_scatter = hvplot.custom_scatter(y='y')
     scatter = hvplot.scatter(y='y')
     custom_opts = Store.lookup_options('bokeh', custom_scatter, 'plot')
     opts = Store.lookup_options('bokeh', scatter, 'plot')
     self.assertEqual(custom_opts.options.get('width'), 42)
     self.assertEqual(custom_opts.options.get('height'), 42)
     self.assertNotEqual(opts.options.get('width'), 42)
     self.assertNotEqual(opts.options.get('height'), 42)
예제 #16
0
    def test_style_transfer(self):
        if 'matplotlib' not in Store.renderers:
            raise SkipTest("test_style_transfer requires matplotlib")

        hist = self.hist.opts(style={'style1': 'style_child'})
        hist2 = self.hist.opts()
        opts = Store.lookup_options('matplotlib', hist2, 'style').kwargs
        self.assertEqual(opts, {'style1': 'style1', 'style2': 'style2'})
        Store.transfer_options(hist, hist2, 'matplotlib')
        opts = Store.lookup_options('matplotlib', hist2, 'style').kwargs
        self.assertEqual(opts, {'style1': 'style_child', 'style2': 'style2'})
예제 #17
0
    def test_style_transfer(self):
        if 'matplotlib' not in Store.renderers:
            raise SkipTest("test_style_transfer requires matplotlib")

        hist = self.hist.opts(style={'style1':'style_child'})
        hist2 = self.hist.opts()
        opts = Store.lookup_options('matplotlib', hist2, 'style').kwargs
        self.assertEqual(opts, {'style1': 'style1', 'style2': 'style2'})
        Store.transfer_options(hist, hist2, 'matplotlib')
        opts = Store.lookup_options('matplotlib', hist2, 'style').kwargs
        self.assertEqual(opts, {'style1': 'style_child', 'style2': 'style2'})
예제 #18
0
 def test_mpl_bokeh_mpl_via_builders_opts_method(self):
     img = Image(np.random.rand(10,10))
     mpl_opts = opts.Image(cmap='Blues', backend='matplotlib')
     bokeh_opts = opts.Image(cmap='Purple', backend='bokeh')
     self.assertEqual(mpl_opts.kwargs['backend'], 'matplotlib')
     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)
예제 #19
0
 def test_aspect_and_frame_height_with_datashade_and_dynamic_is_false(self, opt):
     plot = self.df.hvplot(x='x', y='y', frame_height=150, datashade=True, dynamic=False, **{opt: 2})
     opts = Store.lookup_options('bokeh', plot[()], 'plot').kwargs
     self.assertEqual(opts[opt], 2)
     self.assertEqual(opts.get('frame_height'), 150)
     self.assertEqual(opts.get('height'), None)
     self.assertEqual(opts.get('frame_width'), None)
예제 #20
0
 def test_cmap_opts_as_a_list(self):
     plot = self.df.hvplot.scatter('x',
                                   'y',
                                   c='number',
                                   cmap=['red', 'blue', 'green'])
     opts = Store.lookup_options('bokeh', plot, 'style')
     self.assertEqual(opts.kwargs['cmap'], ['red', 'blue', 'green'])
예제 #21
0
    def test_specification_general_to_specific_group_and_label(self):
        """
        Test order of specification starting with general and moving
        to specific
        """
        if 'matplotlib' not in Store.renderers:
            raise SkipTest("General to specific option test requires matplotlib")

        options = self.initialize_option_tree()

        obj = Image(np.random.rand(10,10), group='SomeGroup', label='SomeLabel')

        options.Image = Options('style', cmap='viridis')
        options.Image.SomeGroup.SomeLabel = Options('style', alpha=0.2)

        expected = {'alpha': 0.2, 'cmap': 'viridis', 'interpolation': 'nearest'}
        lookup = Store.lookup_options('matplotlib', obj, 'style')

        self.assertEqual(lookup.kwargs, expected)
        # Check the tree is structured as expected
        node1 = options.Image.groups['style']
        node2 = options.Image.SomeGroup.SomeLabel.groups['style']

        self.assertEqual(node1.kwargs, {'cmap': 'viridis', 'interpolation': 'nearest'})
        self.assertEqual(node2.kwargs, {'alpha': 0.2})
예제 #22
0
 def test_holoviews_defined_default_opts_are_not_mutable(self):
     hv.opts.defaults(hv.opts.Scatter(tools=['tap']))
     plot = self.df.hvplot.scatter('x', 'y', c='category')
     opts = Store.lookup_options('bokeh', plot, 'plot')
     self.assertEqual(opts.kwargs['tools'], ['tap', 'hover'])
     default_opts = Store.options(backend='bokeh')['Scatter'].groups['plot'].options
     self.assertEqual(default_opts['tools'], ['tap'])
예제 #23
0
 def test_holoviews_defined_default_opts_logx_overwritten_in_call(self):
     hv.opts.defaults(hv.opts.Scatter(logx=True))
     plot = self.df.hvplot.scatter('x', 'y', c='category', logx=False)
     opts = Store.lookup_options('bokeh', plot, 'plot')
     self.assertEqual(opts.kwargs['logx'], False)
     self.assertEqual(opts.kwargs['logy'], False)
     self.assertEqual(opts.kwargs.get('logz'), None)
예제 #24
0
 def test_bivariate_opts(self):
     plot = self.df.hvplot.bivariate('x', 'y', bandwidth=0.2, cut=1, levels=5, filled=True)
     opts = Store.lookup_options('bokeh', plot, 'plot')
     self.assertEqual(opts.kwargs['bandwidth'], 0.2)
     self.assertEqual(opts.kwargs['cut'], 1)
     self.assertEqual(opts.kwargs['levels'], 5)
     self.assertEqual(opts.kwargs['filled'], True)
예제 #25
0
    def test_specification_specific_to_general_group_and_label(self):
        """
        Test order of specification starting with general and moving
        to specific
        """
        if 'matplotlib' not in Store.renderers:
            raise SkipTest(
                "General to specific option test requires matplotlib")

        options = self.initialize_option_tree()
        options.Image.SomeGroup.SomeLabel = Options('style', alpha=0.2)
        obj = Image(np.random.rand(10, 10),
                    group='SomeGroup',
                    label='SomeLabel')

        options.Image = Options('style', cmap='viridis')
        expected = {
            'alpha': 0.2,
            'cmap': 'viridis',
            'interpolation': 'nearest'
        }
        lookup = Store.lookup_options('matplotlib', obj, 'style')

        self.assertEqual(lookup.kwargs, expected)
        # Check the tree is structured as expected
        node1 = options.Image.groups['style']
        node2 = options.Image.SomeGroup.SomeLabel.groups['style']

        self.assertEqual(node1.kwargs, {
            'cmap': 'viridis',
            'interpolation': 'nearest'
        })
        self.assertEqual(node2.kwargs, {'alpha': 0.2})
예제 #26
0
 def test_scatter_color_by_legend_position(self):
     plot = self.cat_df.hvplot.scatter('x',
                                       'y',
                                       c='category',
                                       legend='left')
     opts = Store.lookup_options('bokeh', plot, 'plot')
     self.assertEqual(opts.kwargs['legend_position'], 'left')
예제 #27
0
 def test_wide_chart_legend_position(self, kind, element):
     plot = self.df.hvplot(kind=kind,
                           value_label='Test',
                           group_label='Category',
                           legend='left')
     opts = Store.lookup_options('bokeh', plot, 'plot')
     self.assertEqual(opts.kwargs['legend_position'], 'left')
예제 #28
0
 def test_rasterize_color_dim_with_new_column_gets_default_cmap(self):
     plot = self.df.hvplot.scatter('x',
                                   'y',
                                   c='y',
                                   dynamic=False,
                                   rasterize=True)
     opts = Store.lookup_options('bokeh', plot, 'style').kwargs
     self.assertEqual(opts.get('cmap'), 'kbc_r')
예제 #29
0
 def test_holoviews_defined_default_opts_overwritten_in_call(self):
     hv.opts.defaults(hv.opts.Scatter(height=400, width=900, show_grid=True))
     plot = self.df.hvplot.scatter('x', 'y', c='category', width=300, legend='left')
     opts = Store.lookup_options('bokeh', plot, 'plot')
     self.assertEqual(opts.kwargs['legend_position'], 'left')
     self.assertEqual(opts.kwargs['show_grid'], True)
     self.assertEqual(opts.kwargs['height'], 400)
     self.assertEqual(opts.kwargs['width'], 300)
예제 #30
0
 def test_tidy_chart_index_by_legend_position(self, kind, element):
     plot = self.df.hvplot(x='index',
                           y='y',
                           by='x',
                           kind=kind,
                           legend='left')
     opts = Store.lookup_options('bokeh', plot, 'plot')
     self.assertEqual(opts.kwargs['legend_position'], 'left')
예제 #31
0
 def test_rasterize_set_clim(self):
     plot = self.df.hvplot.scatter('x',
                                   'y',
                                   dynamic=False,
                                   rasterize=True,
                                   clim=(1, 4))
     opts = Store.lookup_options('bokeh', plot, 'plot').kwargs
     self.assertEqual(opts.get('clim'), (1, 4))
예제 #32
0
    def test_cell_opts_util_style(self):
        mat1 = hv.Image(np.random.rand(5, 5), name='mat1')
        self.assertEqual(mat1.id, None)
        opts("Image (cmap='hot')", mat1)
        self.assertNotEqual(mat1.id, None)

        self.assertEqual(
            Store.lookup_options('matplotlib', mat1,
                                 'style').options.get('cmap', None), 'hot')
예제 #33
0
 def test_axis_set_to_false(self):
     plot = self.df.hvplot.scatter('x',
                                   'y',
                                   c='category',
                                   xaxis=False,
                                   yaxis=False)
     opts = Store.lookup_options('bokeh', plot, 'plot')
     self.assertEqual(opts.kwargs['xaxis'], None)
     self.assertEqual(opts.kwargs['yaxis'], None)
예제 #34
0
    def test_custom_call_to_default_inheritance(self):
        """
        Checks customs inheritance backs off to default tree correctly
        using __call__.
        """
        options = self.initialize_option_tree()
        options.Image.A.B = Options('style', alpha=0.2)

        obj = Image(np.random.rand(10, 10), group='A', label='B')
        expected_obj =  {'alpha': 0.2, 'cmap': 'hot', 'interpolation': 'nearest'}
        obj_lookup = Store.lookup_options('matplotlib', obj, 'style')
        self.assertEqual(obj_lookup.kwargs, expected_obj)

        # Customize this particular object
        custom_obj = obj(style=dict(clims=(0, 0.5)))
        expected_custom_obj =  dict(clims=(0,0.5), **expected_obj)
        custom_obj_lookup = Store.lookup_options('matplotlib', custom_obj, 'style')
        self.assertEqual(custom_obj_lookup.kwargs, expected_custom_obj)
예제 #35
0
    def test_mpl_bokeh_output_options_group_expandable(self):
        original_allowed_kws = Options._output_allowed_kws[:]
        Options._output_allowed_kws = ['backend', 'file_format_example']
        # Re-register
        Store.register({Curve: plotting.mpl.CurvePlot}, 'matplotlib')
        Store.register({Curve: plotting.bokeh.CurvePlot}, 'bokeh')

        curve_bk = Options('Curve', backend='bokeh', color='blue')
        curve_mpl = Options('Curve', backend='matplotlib', color='red',
                            file_format_example='SVG')
        c = Curve([1,2,3])
        styled = c.opts(curve_bk, curve_mpl)
        self.assertEqual(Store.lookup_options('matplotlib', styled, 'output').kwargs,
                         {'backend':'matplotlib', 'file_format_example':'SVG'})

        self.assertEqual(Store.lookup_options('bokeh', styled, 'output').kwargs,
                         {})
        Options._output_allowed_kws = original_allowed_kws
예제 #36
0
    def test_custom_opts_to_default_inheritance(self):
        """
        Checks customs inheritance backs off to default tree correctly
        using .opts.
        """
        options = self.initialize_option_tree()
        options.Image.A.B = Options('style', alpha=0.2)

        obj = Image(np.random.rand(10, 10), group='A', label='B')
        expected_obj =  {'alpha': 0.2, 'cmap': 'hot', 'interpolation': 'nearest'}
        obj_lookup = Store.lookup_options('matplotlib', obj, 'style')
        self.assertEqual(obj_lookup.kwargs, expected_obj)

        # Customize this particular object
        custom_obj = obj.opts(style=dict(clims=(0, 0.5)))
        expected_custom_obj =  dict(clims=(0,0.5), **expected_obj)
        custom_obj_lookup = Store.lookup_options('matplotlib', custom_obj, 'style')
        self.assertEqual(custom_obj_lookup.kwargs, expected_custom_obj)
예제 #37
0
 def test_scatter_size_set_to_series(self):
     if is_dask(self.df['y']):
         y = self.df['y'].compute()
     else:
         y = self.df['y']
     plot = self.df.hvplot.scatter('x', 'y', s=y)
     opts = Store.lookup_options('bokeh', plot, 'style')
     assert '_size' in plot.data.columns
     self.assertEqual(opts.kwargs['size'], '_size')
예제 #38
0
    def test_cell_opts_util_style(self):
        mat1 = hv.Image(np.random.rand(5,5), name='mat1')
        self.assertEqual(mat1.id, None)
        opts("Image (cmap='hot')", mat1)
        self.assertNotEqual(mat1.id, None)

        self.assertEqual(
             Store.lookup_options('matplotlib',
                                  mat1, 'style').options.get('cmap',None),'hot')
예제 #39
0
    def test_cell_opts_util_norm(self):
        mat1 = hv.Image(np.random.rand(5, 5), name='mat1')
        self.assertEqual(mat1.id, None)
        opts("Image {+axiswise}", mat1)
        self.assertNotEqual(mat1.id, None)

        self.assertEqual(
            Store.lookup_options('matplotlib', mat1,
                                 'norm').options.get('axiswise', True), True)
예제 #40
0
 def test_alpha_dim_overlay(self, kind):
     plot = self.df.hvplot('x',
                           'y',
                           alpha='number',
                           by='category',
                           kind=kind)
     opts = Store.lookup_options('bokeh', plot.last, 'style')
     self.assertEqual(opts.kwargs['alpha'], 'number')
     self.assertIn('number', plot.last.vdims)
예제 #41
0
 def test_tidy_chart_ranges(self, kind, element):
     plot = self.df.hvplot(x='x',
                           y='y',
                           kind=kind,
                           xlim=(0, 3),
                           ylim=(5, 10))
     opts = Store.lookup_options('bokeh', plot, 'plot').options
     self.assertEqual(opts['xlim'], (0, 3))
     self.assertEqual(opts['ylim'], (5, 10))
예제 #42
0
    def test_cell_opts_util_norm(self):
        mat1 = hv.Image(np.random.rand(5,5), name='mat1')
        self.assertEqual(mat1.id, None)
        opts("Image {+axiswise}", mat1)
        self.assertNotEqual(mat1.id, None)

        self.assertEqual(
            Store.lookup_options('matplotlib',
                                 mat1, 'norm').options.get('axiswise',True), True)
예제 #43
0
 def test_pickle_mpl_bokeh(self):
     """
     Test pickle saving and loading with Store (style information preserved)
     """
     fname = 'test_pickle_mpl_bokeh.pkl'
     raw = super(TestCrossBackendOptionPickling, self).test_mpl_bokeh_mpl()
     Store.dump(raw, open(fname,'wb'))
     self.clear_options()
     img = Store.load(open(fname,'rb'))
     # Data should match
     self.assertEqual(raw, img)
     # Check it is still blue in matplotlib...
     Store.current_backend = 'matplotlib'
     mpl_opts = Store.lookup_options('matplotlib', img, 'style').options
     self.assertEqual(mpl_opts, {'cmap':'Blues'})
     # And purple in bokeh..
     Store.current_backend = 'bokeh'
     bokeh_opts = Store.lookup_options('bokeh', img, 'style').options
     self.assertEqual(bokeh_opts, {'cmap':'Purple'})
예제 #44
0
    def test_cell_opts_util_plot(self):

        mat1 = hv.Image(np.random.rand(5,5), name='mat1')

        self.assertEqual(mat1.id, None)
        opts("Image [show_title=False]", mat1)
        self.assertNotEqual(mat1.id, None)
        self.assertEqual(
            Store.lookup_options('matplotlib',
                                 mat1, 'plot').options.get('show_title',True),False)
예제 #45
0
 def test_raw_pickle(self):
     """
     Test usual pickle saving and loading (no style information preserved)
     """
     fname= 'test_raw_pickle.pkl'
     raw = super(TestCrossBackendOptionPickling, self).test_mpl_bokeh_mpl()
     pickle.dump(raw, open(fname,'wb'))
     self.clear_options()
     img = pickle.load(open(fname,'rb'))
     # Data should match
     self.assertEqual(raw, img)
     # But the styles will be lost without using Store.load/Store.dump
     pickle.current_backend = 'matplotlib'
     mpl_opts = Store.lookup_options('matplotlib', img, 'style').options
     self.assertEqual(mpl_opts, {})
     # ... across all backends
     Store.current_backend = 'bokeh'
     bokeh_opts = Store.lookup_options('bokeh', img, 'style').options
     self.assertEqual(bokeh_opts, {})
예제 #46
0
    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')
예제 #47
0
 def assert_output_options_group_empty(self, obj):
     mpl_output_lookup = Store.lookup_options('matplotlib', obj, 'output').options
     self.assertEqual(mpl_output_lookup, {})
     bokeh_output_lookup = Store.lookup_options('bokeh', obj, 'output').options
     self.assertEqual(bokeh_output_lookup, {})
예제 #48
0
 def lookup_options(self, obj, group):
     return Store.lookup_options(self.backend, obj, group)
예제 #49
0
 def test_style_inheritance_override(self):
     "Overriding an element"
     hist2 = self.hist(style={"style1": "style_child"})
     self.assertEqual(Store.lookup_options(hist2, "style").options, dict(style1="style_child", style2="style2"))
     # Check plot options works as expected
     self.assertEqual(Store.lookup_options(hist2, "plot").options, self.default_plot)
예제 #50
0
 def test_plot_inheritance_override(self):
     "Overriding an element"
     hist2 = self.hist(plot={"plot1": "plot_child"})
     self.assertEqual(Store.lookup_options(hist2, "plot").options, dict(plot1="plot_child", plot2="plot2"))
     # Check style works as expected
     self.assertEqual(Store.lookup_options(hist2, "style").options, self.default_style)
예제 #51
0
 def test_plot_inheritance_addition(self):
     "Adding an element"
     hist2 = self.hist(plot={"plot3": "plot3"})
     self.assertEqual(Store.lookup_options(hist2, "plot").options, dict(plot1="plot1", plot2="plot2", plot3="plot3"))
     # Check style works as expected
     self.assertEqual(Store.lookup_options(hist2, "style").options, self.default_style)
예제 #52
0
 def test_original_plot_options(self):
     self.assertEqual(Store.lookup_options(self.hist, "plot").options, self.default_plot)
예제 #53
0
 def test_original_style_options(self):
     self.assertEqual(Store.lookup_options(self.hist, "style").options, self.default_style)