示例#1
0
    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)
示例#2
0
 def clear_options(self):
     # Clear global options..
     Store.options(val=OptionTree(groups=['plot', 'style']), backend='matplotlib')
     Store.options(val=OptionTree(groups=['plot', 'style']), backend='bokeh')
     # ... and custom options
     Store.custom_options({}, backend='matplotlib')
     Store.custom_options({}, backend='bokeh')
示例#3
0
    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)
示例#4
0
 def clear_options(self):
     # Clear global options..
     Store.options(val=OptionTree(groups=['plot', 'style']), backend='matplotlib')
     Store.options(val=OptionTree(groups=['plot', 'style']), backend='bokeh')
     # ... and custom options
     Store.custom_options({}, backend='matplotlib')
     Store.custom_options({}, backend='bokeh')
示例#5
0
    def tearDown(self):
        Store.options(val=self.store_mpl, backend='matplotlib')
        Store.options(val=self.store_bokeh, backend='bokeh')
        Store.current_backend = 'matplotlib'
        Store._custom_options = {k:{} for k in Store._custom_options.keys()}

        if self.plotly_options is not None:
            Store._options['plotly'] = self.plotly_options

        super(TestCrossBackendOptionSpecification, self).tearDown()
示例#6
0
    def setUp(self):

        if 'bokeh' not in Store.renderers:
            raise SkipTest("Cross background tests assumes bokeh is available.")
        self.store_mpl = OptionTree(sorted(Store.options(backend='matplotlib').items()),
                                    groups=['style', 'plot', 'norm'])
        self.store_bokeh = OptionTree(sorted(Store.options(backend='bokeh').items()),
                                    groups=['style', 'plot', 'norm'])
        self.clear_options()
        super(TestCrossBackendOptions, self).setUp()
示例#7
0
    def tearDown(self):
        Store.options(val=self.store_mpl, backend='matplotlib')
        Store.options(val=self.store_bokeh, backend='bokeh')
        Store.current_backend = 'matplotlib'
        Store._custom_options = {k: {} for k in Store._custom_options.keys()}

        if self.plotly_options is not None:
            Store._options['plotly'] = self.plotly_options

        super(TestCrossBackendOptions, self).tearDown()
示例#8
0
    def setUp(self):
        if 'matplotlib' not in Store.renderers:
            raise SkipTest("Cross background tests assumes matplotlib is available")
        if 'bokeh' not in Store.renderers:
            raise SkipTest("Cross background tests assumes bokeh is available.")

        # Some tests require that plotly isn't loaded
        self.plotly_options = Store._options.pop('plotly', None)
        self.store_mpl = OptionTree(sorted(Store.options(backend='matplotlib').items()),
                                    groups=Options._option_groups)
        self.store_bokeh = OptionTree(sorted(Store.options(backend='bokeh').items()),
                                    groups=Options._option_groups)
        super(TestCrossBackendOptionSpecification, self).setUp()
示例#9
0
    def setUp(self):

        if 'bokeh' not in Store.renderers:
            raise SkipTest(
                "Cross background tests assumes bokeh is available.")
        self.store_mpl = OptionTree(sorted(
            Store.options(backend='matplotlib').items()),
                                    groups=['style', 'plot', 'norm'])
        self.store_bokeh = OptionTree(sorted(
            Store.options(backend='bokeh').items()),
                                      groups=['style', 'plot', 'norm'])
        self.clear_options()
        super(TestCrossBackendOptions, self).setUp()
示例#10
0
    def setUp(self):
        if 'matplotlib' not in Store.renderers:
            raise SkipTest("Cross background tests assumes matplotlib is available")
        if 'bokeh' not in Store.renderers:
            raise SkipTest("Cross background tests assumes bokeh is available.")

        # Some tests require that plotly isn't loaded
        self.plotly_options = Store._options.pop('plotly', None)
        self.store_mpl = OptionTree(sorted(Store.options(backend='matplotlib').items()),
                                    groups=['style', 'plot', 'norm'])
        self.store_bokeh = OptionTree(sorted(Store.options(backend='bokeh').items()),
                                    groups=['style', 'plot', 'norm'])
        self.clear_options()
        super(TestCrossBackendOptions, self).setUp()
示例#11
0
 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)
示例#12
0
 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)
示例#13
0
 def setUp(self):
     try:
         import xarray as xr
     except:
         raise SkipTest('Xarray not available')
     self.backend = 'bokeh'
     hv.extension(self.backend)
     Store.current_backend = self.backend
     self.store_copy = OptionTree(sorted(Store.options().items()),
                                  groups=Options._option_groups)
     import hvplot.xarray  # noqa
     self.da = xr.DataArray(
         data=np.arange(16).reshape((2, 2, 2, 2)),
         coords={
             'time': [0, 1],
             'y': [0, 1],
             'x': [0, 1],
             'band': [0, 1]
         },
         dims=['time', 'y', 'x', 'band'],
         name='test',
     )
     da2 = xr.DataArray(data=np.arange(27).reshape((3, 3, 3)),
                        coords={
                            'y': [0, 1, 2],
                            'x': [0, 1, 2]
                        },
                        dims=['y', 'x', 'other'],
                        name='test2')
     self.ds1 = xr.Dataset(dict(foo=self.da))
     self.ds2 = xr.Dataset(dict(foo=self.da, bar=da2))
示例#14
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'])
示例#15
0
 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.current_backend = self.backend
     super(TestStoreInheritanceDynamic, self).setUp()
示例#16
0
 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.current_backend = self.backend
     super(TestStoreInheritanceDynamic, self).setUp()
示例#17
0
 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()
示例#18
0
 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()
示例#19
0
def init_notebook(mpl=True):
    # Enable inline plotting in the notebook
    if mpl:
        try:
            get_ipython().enable_matplotlib(gui='inline')
        except NameError:
            pass

    print('Populated the namespace with:\n' +
        ', '.join(init_mooc_nb) +
        '\nfrom code/edx_components:\n' +
        ', '.join(edx_components.__all__) +
        '\nfrom code/functions:\n' +
        ', '.join(functions.__all__))

    holoviews.notebook_extension('matplotlib')

    Store.renderers['matplotlib'].fig = 'svg'

    holoviews.plotting.mpl.MPLPlot.fig_rcparams['text.usetex'] = True
    
    latex_packs = [r'\usepackage{amsmath}',
                   r'\usepackage{amssymb}'
                   r'\usepackage{bm}']

    holoviews.plotting.mpl.MPLPlot.fig_rcparams['text.latex.preamble'] = latex_packs

    # Set plot style.
    options = Store.options(backend='matplotlib')
    options.Contours = Options('style', linewidth=2, color='k')
    options.Contours = Options('plot', aspect='square')
    options.HLine = Options('style', linestyle='--', color='b', linewidth=2)
    options.VLine = Options('style', linestyle='--', color='r', linewidth=2)
    options.Image = Options('style', cmap='RdBu_r')
    options.Image = Options('plot', title_format='{label}')
    options.Path = Options('style', linewidth=1.2, color='k')
    options.Path = Options('plot', aspect='square', title_format='{label}')
    options.Curve = Options('style', linewidth=2, color='k')
    options.Curve = Options('plot', aspect='square', title_format='{label}')
    options.Overlay = Options('plot', show_legend=False, title_format='{label}')
    options.Layout = Options('plot', title_format='{label}')
    options.Surface = Options('style', cmap='RdBu_r', rstride=1, cstride=1, lw=0.2)
    options.Surface = Options('plot', azimuth=20, elevation=8)

    # Turn off a bogus holoviews warning.
    # Temporary solution to ignore the warnings
    warnings.filterwarnings('ignore', r'All-NaN (slice|axis) encountered')

    module_dir = os.path.dirname(__file__)
    matplotlib.rc_file(os.path.join(module_dir, "matplotlibrc"))

    np.set_printoptions(precision=2, suppress=True,
                        formatter={'complexfloat': pretty_fmt_complex})

    # Patch a bug in holoviews
    if holoviews.__version__.release <= (1, 4, 3):
        from patch_holoviews import patch_all
        patch_all()
示例#20
0
    def setUp(self):
        self.store_copy = OptionTree(sorted(Store.options().items()),
                                     groups=['style', 'plot', 'norm'])
        self.backend = 'matplotlib'
        Store.current_backend = self.backend
        Store.options(val=OptionTree(groups=['plot', 'style']))

        options = Store.options()

        self.default_plot = dict(plot1='plot1', plot2='plot2')
        options.Histogram = Options('plot', **self.default_plot)

        self.default_style = dict(style1='style1', style2='style2')
        options.Histogram = Options('style', **self.default_style)

        data = [np.random.normal() for i in range(10000)]
        frequencies, edges = np.histogram(data, 20)
        self.hist = Histogram(frequencies, edges)
        super(TestStoreInheritance, self).setUp()
示例#21
0
    def setUp(self):
        options = OptionTree(groups=['group'])
        self.opts1 = Options('group', kw1='value1')
        self.opts2 = Options('group', kw2='value2')
        self.opts3 = Options('group', kw3='value3')
        self.opts4 = Options('group', kw4='value4')
        self.opts5 = Options('group', kw5='value5')
        self.opts6 = Options('group', kw6='value6')

        options.MyType = self.opts1
        options.XType = self.opts2
        options.MyType.Foo = self.opts3
        options.MyType.Bar = self.opts4
        options.XType.Foo = self.opts5
        options.XType.Bar = self.opts6

        self.options = options
        self.original_options = Store.options()
        Store.options(val = OptionTree(groups=['group']))
示例#22
0
    def setUp(self):
        self.store_copy = OptionTree(sorted(Store.options().items()),
                                     groups=['style', 'plot', 'norm'])
        self.backend = 'matplotlib'
        Store.current_backend = self.backend
        Store.options(val=OptionTree(groups=['plot', 'style']))

        options = Store.options()

        self.default_plot = dict(plot1='plot1', plot2='plot2')
        options.Histogram = Options('plot', **self.default_plot)

        self.default_style = dict(style1='style1', style2='style2')
        options.Histogram = Options('style', **self.default_style)

        data = [np.random.normal() for i in range(10000)]
        frequencies, edges = np.histogram(data, 20)
        self.hist = Histogram(frequencies, edges)
        super(TestStoreInheritance, self).setUp()
示例#23
0
    def setUp(self):
        options = OptionTree(groups=['group'])
        self.opts1 = Options('group', kw1='value1')
        self.opts2 = Options('group', kw2='value2')
        self.opts3 = Options('group', kw3='value3')
        self.opts4 = Options('group', kw4='value4')
        self.opts5 = Options('group', kw5='value5')
        self.opts6 = Options('group', kw6='value6')

        options.MyType = self.opts1
        options.XType = self.opts2
        options.MyType.Foo = self.opts3
        options.MyType.Bar = self.opts4
        options.XType.Foo = self.opts5
        options.XType.Bar = self.opts6

        self.options = options
        self.original_options = Store.options()
        Store.options(val=OptionTree(groups=['group']))
示例#24
0
def init_notebook():
    # Enable inline plotting in the notebook
    try:
        get_ipython().enable_matplotlib(gui='inline')
    except NameError:
        pass

    print('Populated the namespace with:\n' + ', '.join(__all__))
    holoviews.notebook_extension('matplotlib')
    holoviews.plotting.mpl.MPLPlot.fig_rcparams['text.usetex'] = True

    # Set plot style.
    options = Store.options(backend='matplotlib')
    options.Contours = Options('style', linewidth=2, color='k')
    options.Contours = Options('plot', aspect='square')
    options.HLine = Options('style', linestyle='--', color='b', linewidth=2)
    options.VLine = Options('style', linestyle='--', color='r', linewidth=2)
    options.Image = Options('style', cmap='RdBu_r')
    options.Image = Options('plot', title_format='{label}')
    options.Path = Options('style', linewidth=1.2, color='k')
    options.Path = Options('plot', aspect='square', title_format='{label}')
    options.Curve = Options('style', linewidth=2, color='k')
    options.Curve = Options('plot', aspect='square', title_format='{label}')
    options.Overlay = Options('plot', show_legend=False, title_format='{label}')
    options.Layout = Options('plot', title_format='{label}')
    options.Surface = Options('style', cmap='RdBu_r', rstride=1, cstride=1, lw=0.2)
    options.Surface = Options('plot', azimuth=20, elevation=8)

    # Turn off a bogus holoviews warning.
    # Temporary solution to ignore the warnings
    warnings.filterwarnings('ignore', r'All-NaN (slice|axis) encountered')

    module_dir = os.path.dirname(__file__)
    matplotlib.rc_file(os.path.join(module_dir, "matplotlibrc"))

    np.set_printoptions(precision=2, suppress=True,
                        formatter={'complexfloat': pretty_fmt_complex})

    # In order to make the notebooks readable through nbviewer we want to hide
    # the code by default. However the same code is executed by the students,
    # and in that case we don't want to hide the code. So we check if the code
    # is executed by one of the mooc developers. Here we do by simply checking
    # for some files that belong to the internal mooc repository, but are not
    # published.  This is a temporary solution, and should be improved in the
    # long run.

    developer = os.path.exists(os.path.join(module_dir, os.path.pardir,
                                            'scripts'))

    display_html(display.HTML(nb_html_header +
                              (hide_outside_ipython if developer else '')))

    # Patch a bug in holoviews
    from patch_holoviews import patch_all
    patch_all()
示例#25
0
 def setUp(self):
     try:
         import pandas as pd
     except:
         raise SkipTest('Pandas not available')
     self.backend = 'bokeh'
     hv.extension(self.backend)
     Store.current_backend = self.backend
     self.store_copy = OptionTree(sorted(Store.options().items()),
                                  groups=Options._option_groups)
     patch('pandas')
     self.df = pd.DataFrame([[1, 2, 'A', 0.1], [3, 4, 'B', 0.2], [5, 6, 'C', 0.3]],
                            columns=['x', 'y', 'category', 'number'])
示例#26
0
def init_notebook():
    print_information()
    check_versions()

    code_dir = os.path.dirname(os.path.realpath(__file__))
    hv_css = os.path.join(code_dir, 'hv_widgets_settings.css')
    holoviews.plotting.widgets.SelectionWidget.css = hv_css

    holoviews.notebook_extension('matplotlib')

    # Enable inline plotting in the notebook
    get_ipython().enable_matplotlib(gui='inline')

    Store.renderers['matplotlib'].fig = 'svg'
    Store.renderers['matplotlib'].dpi = 100

    holoviews.plotting.mpl.MPLPlot.fig_rcparams['text.usetex'] = True

    latex_packs = [r'\usepackage{amsmath}',
                   r'\usepackage{amssymb}'
                   r'\usepackage{bm}']

    holoviews.plotting.mpl.MPLPlot.fig_rcparams['text.latex.preamble'] = \
        latex_packs

    # Set plot style.
    options = Store.options(backend='matplotlib')
    options.Contours = Options('style', linewidth=2, color='k')
    options.Contours = Options('plot', aspect='square')
    options.HLine = Options('style', linestyle='--', color='b', linewidth=2)
    options.VLine = Options('style', linestyle='--', color='r', linewidth=2)
    options.Image = Options('style', cmap='RdBu_r')
    options.Image = Options('plot', title_format='{label}')
    options.Path = Options('style', linewidth=1.2, color='k')
    options.Path = Options('plot', aspect='square', title_format='{label}')
    options.Curve = Options('style', linewidth=2, color='k')
    options.Curve = Options('plot', aspect='square', title_format='{label}')
    options.Overlay = Options('plot', show_legend=False, title_format='{label}')
    options.Layout = Options('plot', title_format='{label}')
    options.Surface = Options('style', cmap='RdBu_r', rstride=2, cstride=2,
                              lw=0.2, edgecolors='k')
    options.Surface = Options('plot', azimuth=20, elevation=8)

    # Set slider label formatting
    for dimension_type in [float, np.float64, np.float32]:
        holoviews.Dimension.type_formatters[dimension_type] = pretty_fmt_complex

    matplotlib.rc_file(os.path.join(code_dir, "matplotlibrc"))

    np.set_printoptions(precision=2, suppress=True,
                        formatter={'complexfloat': pretty_fmt_complex})
示例#27
0
def init_notebook():
    print_information()
    check_versions()

    code_dir = os.path.dirname(os.path.realpath(__file__))
    hv_css = os.path.join(code_dir, 'hv_widgets_settings.css')
    holoviews.plotting.widgets.SelectionWidget.css = hv_css

    holoviews.notebook_extension('matplotlib')

    # Enable inline plotting in the notebook
    get_ipython().enable_matplotlib(gui='inline')

    Store.renderers['matplotlib'].fig = 'svg'
    Store.renderers['matplotlib'].dpi = 100

    holoviews.plotting.mpl.MPLPlot.fig_rcparams['text.usetex'] = True

    latex_packs = [r'\usepackage{amsmath}',
                   r'\usepackage{amssymb}'
                   r'\usepackage{bm}']

    holoviews.plotting.mpl.MPLPlot.fig_rcparams['text.latex.preamble'] = \
        latex_packs

    # Set plot style.
    options = Store.options(backend='matplotlib')
    options.Contours = Options('style', linewidth=2, color='k')
    options.Contours = Options('plot', aspect='square')
    options.HLine = Options('style', linestyle='--', color='b', linewidth=2)
    options.VLine = Options('style', linestyle='--', color='r', linewidth=2)
    options.Image = Options('style', cmap='RdBu_r')
    options.Image = Options('plot', title_format='{label}')
    options.Path = Options('style', linewidth=1.2, color='k')
    options.Path = Options('plot', aspect='square', title_format='{label}')
    options.Curve = Options('style', linewidth=2, color='k')
    options.Curve = Options('plot', aspect='square', title_format='{label}')
    options.Overlay = Options('plot', show_legend=False, title_format='{label}')
    options.Layout = Options('plot', title_format='{label}')
    options.Surface = Options('style', cmap='RdBu_r', rstride=2, cstride=2,
                              lw=0.2, edgecolors='k')
    options.Surface = Options('plot', azimuth=20, elevation=8)

    # Set slider label formatting
    for dimension_type in [float, np.float64, np.float32]:
        holoviews.Dimension.type_formatters[dimension_type] = pretty_fmt_complex

    matplotlib.rc_file(os.path.join(code_dir, "matplotlibrc"))

    np.set_printoptions(precision=2, suppress=True,
                        formatter={'complexfloat': pretty_fmt_complex})
示例#28
0
 def initialize_option_tree(self):
     Store.options(val=OptionTree(groups=['plot', 'style']))
     options = Store.options()
     options.Image = Options('style', cmap='hot', interpolation='nearest')
     return options
示例#29
0
            deltas, weights = [], []
            for k, cf in cfs.items():
                preferred = featurepref[k]
                weight_arr = cf.situated.data.flat
                feature_slice = feature_arr[weight_arr>0]
                weight_slice = weight_arr[weight_arr>0]
                if feature.cyclic:
                    feature_delta = circular_dist(preferred, feature_slice, feature.range[1])
                else:
                    feature_delta = np.abs(feature_slice-preferred)
                deltas.append(feature_delta)
                weights.append(weight_slice)
            deltas = np.concatenate(deltas)
            weights = np.concatenate(weights)
            bin_range = (0, feature.range[1]/2.) if feature.cyclic else None
            bins, edges = np.histogram(deltas, range=bin_range, bins=self.p.num_bins,
                                       weights=weights, normed=self.p.normalized)
            # Construct Elements
            label = ' '.join([s,p])
            group = '%s Weight Distribution' % self.p.feature
            histogram = Histogram(bins, edges, group=group, label=label,
                                  kdims=[' '.join([self.p.feature, 'Difference'])],
                                  vdims=['Weight'])

            layout.WeightDistribution['_'.join([s,p])] = histogram

        return layout

options = Store.options(backend='matplotlib')
options.Histogram.Weight_Isotropy = Options('plot', projection='polar', show_grid=True)
示例#30
0
 def tearDown(self):
     Store.options(val=self.store_mpl, backend='matplotlib')
     Store.options(val=self.store_bokeh, backend='bokeh')
     Store.current_backend = 'matplotlib'
     Store._custom_options = {k:{} for k in Store._custom_options.keys()}
     super(TestCrossBackendOptions, self).tearDown()
示例#31
0
 def setUp(self):
     self.backend = Store.current_backend
     Store.current_backend = 'matplotlib'
     self.store_copy = OptionTree(sorted(Store.options().items()),
                                  groups=Options._option_groups)
     super(TestOptsUtil, self).setUp()
示例#32
0
 def setUp(self):
     self.store_copy = OptionTree(sorted(Store.options().items()),
                                  groups=['style', 'plot', 'norm'])
     self.backend = 'matplotlib'
     Store.current_backend = self.backend
     super(TestStoreInheritanceDynamic, self).setUp()
示例#33
0
 def tearDown(self):
     Store.options(val=self.store_copy)
     Store._custom_options = {k:{} for k in Store._custom_options.keys()}
     super(TestOptsUtil, self).tearDown()
示例#34
0
 def tearDown(self):
     Options._option_groups = self.original_option_groups
     Store.options(val=self.original_options)
     Store._custom_options = {k: {} for k in Store._custom_options.keys()}
示例#35
0
                    feature_delta = circular_dist(preferred, feature_slice, feature.range[1])
                else:
                    feature_delta = np.abs(feature_slice - preferred)
                deltas.append(feature_delta)
                weights.append(weight_slice)
            deltas = np.concatenate(deltas)
            weights = np.concatenate(weights)
            bin_range = (0, feature.range[1] / 2.0) if feature.cyclic else None
            bins, edges = np.histogram(
                deltas, range=bin_range, bins=self.p.num_bins, weights=weights, normed=self.p.normalized
            )
            # Construct Elements
            label = " ".join([s, p])
            group = "%s Weight Distribution" % self.p.feature
            histogram = Histogram(
                bins,
                edges,
                group=group,
                label=label,
                kdims=[" ".join([self.p.feature, "Difference"])],
                vdims=["Weight"],
            )

            layout.WeightDistribution["_".join([s, p])] = histogram

        return layout


options = Store.options(backend="matplotlib")
options.Histogram.Weight_Isotropy = Options("plot", projection="polar", show_grid=True)
示例#36
0
 def initialize_option_tree(self):
     Store.options(val=OptionTree(groups=['plot', 'style']))
     options = Store.options()
     options.Image = Options('style', cmap='hot', interpolation='nearest')
     return options
示例#37
0
Store.register(
    {
        WMTS: TilePlot,
        Points: GeoPointPlot,
        Polygons: GeoPolygonPlot,
        Path: GeoPathPlot,
        Shape: GeoShapePlot,
        Image: GeoRasterPlot,
        Feature: FeaturePlot,
        Text: GeoTextPlot,
        Overlay: OverlayPlot,
        NdOverlay: OverlayPlot
    }, 'bokeh')

options = Store.options(backend='bokeh')

options.Feature = Options('style', line_color='black')
options.Feature.Coastline = Options('style', line_width=0.5)
options.Feature.Borders = Options('style', line_width=0.5)
options.Feature.Rivers = Options('style', line_color='blue')
options.Feature.Land = Options('style',
                               fill_color='#efefdb',
                               line_color='#efefdb')
options.Feature.Ocean = Options('style',
                                fill_color='#97b6e1',
                                line_color='#97b6e1')
options.Feature.Lakes = Options('style',
                                fill_color='#97b6e1',
                                line_color='#97b6e1')
options.Feature.Rivers = Options('style', line_color='#97b6e1')
示例#38
0
 def setUp(self):
     self.store_copy = OptionTree(sorted(Store.options().items()),
                                  groups=['style', 'plot', 'norm'])
     self.backend = 'matplotlib'
     Store.current_backend = self.backend
     super(TestStoreInheritanceDynamic, self).setUp()
示例#39
0
 def tearDown(self):
     Store.options(val=self.store_mpl, backend='matplotlib')
     Store.options(val=self.store_bokeh, backend='bokeh')
     Store.current_backend = 'matplotlib'
     super(TestCrossBackendOptions, self).tearDown()
示例#40
0
 def tearDown(self):
     Store.options(val=self.original_options)
示例#41
0
 def tearDown(self):
     Store.options(val=self.store_copy)
     super(TestStoreInheritance, self).tearDown()
示例#42
0
文件: __init__.py 项目: ioam/geoviews
                Contours: GeoContourPlot,
                Path: GeoPathPlot,
                Shape: GeoShapePlot,
                Image: GeoRasterPlot,
                RGB: GeoRGBPlot,
                LineContours: LineContourPlot,
                FilledContours: FilledContourPlot,
                Feature: FeaturePlot,
                HexTiles: HexTilesPlot,
                Text: GeoTextPlot,
                Overlay: GeoOverlayPlot,
                NdOverlay: GeoOverlayPlot,
                Graph: GeoGraphPlot,
                TriMesh: GeoTriMeshPlot,
                Nodes: GeoPointPlot,
                EdgePaths: GeoPathPlot,
                QuadMesh: GeoQuadMeshPlot}, 'bokeh')

options = Store.options(backend='bokeh')

options.Feature = Options('style', line_color='black')
options.Feature.Coastline = Options('style', line_width=0.5)
options.Feature.Borders = Options('style', line_width=0.5)
options.Feature.Rivers = Options('style', line_color='blue')
options.Feature.Land   = Options('style', fill_color='#efefdb', line_color='#efefdb')
options.Feature.Ocean  = Options('style', fill_color='#97b6e1', line_color='#97b6e1')
options.Feature.Lakes  = Options('style', fill_color='#97b6e1', line_color='#97b6e1')
options.Feature.Rivers = Options('style', line_color='#97b6e1')
options.Feature.Grid = Options('style', line_width=0.5, alpha=0.5, line_color='gray')
options.Shape = Options('style', line_color='black', fill_color='#30A2DA')
示例#43
0
        return pn.Tabs(('Polygons', self.poly_table),
                       ('Vertices', self.vertex_table),
                       ('Points', self.point_table))


class PolyExporter(param.Parameterized):

    filename = param.String(default='')

    path = param.ClassSelector(class_=Path, precedence=-1)

    save = param.Action(default=lambda x: x._save())

    def __init__(self, path, **params):
        self._polys = paths_to_polys(path)
        super(PolyExporter, self).__init__(path=path, **params)

    def _save(self):
        pass

    def panel(self):
        return pn.Row(self.param, self._polys.options(width=800, height=600))


options = Store.options('bokeh')

options.Points = Options('plot', padding=0.1)
options.Points = Options('style', size=10, line_color='black')
options.Path = Options('plot', padding=0.1)
options.Polygons = Options('plot', padding=0.1)
示例#44
0
 def tearDown(self):
     Store.current_backend = self.backend
     Store.options(val=self.store_copy)
     Store._custom_options = {k: {} for k in Store._custom_options.keys()}
     super(TestOptsUtil, self).tearDown()
示例#45
0
 def tearDown(self):
     Store.options(val=self.store_copy)
     Store._custom_options = {k:{} for k in Store._custom_options.keys()}
     super(TestStoreInheritance, self).tearDown()
示例#46
0
 def tearDown(self):
     Store.options(val=self.store_copy)
     Store._custom_options = {k: {} for k in Store._custom_options.keys()}
     super(TestStoreInheritance, self).tearDown()
示例#47
0
 def setUp(self):
     self.backend = Store.current_backend
     Store.current_backend = 'matplotlib'
     self.store_copy = OptionTree(sorted(Store.options().items()),
                                  groups=Options._option_groups)
     super(TestOptsUtil, self).setUp()
示例#48
0
 def tearDown(self):
     Store.options(val=self.store_copy)
     Store._custom_options = {k: {} for k in Store._custom_options.keys()}
     super(TestOptsMethod, self).tearDown()
示例#49
0
 def tearDown(self):
     Store.options(val=self.original_options)
     Store._custom_options = {k:{} for k in Store._custom_options.keys()}
示例#50
0
    def setUp(self):
        self.store_copy = OptionTree(sorted(Store.options().items()),
                                     groups=['style', 'plot', 'norm'])
        self.backend = 'matplotlib'

        super(TestOptsUtil, self).setUp()
示例#51
0
def init_notebook():
    # Enable inline plotting in the notebook
    try:
        get_ipython().enable_matplotlib(gui='inline')
    except NameError:
        pass

    print('Populated the namespace with:\n' + ', '.join(init_mooc_nb) +
          '\nfrom code/edx_components:\n' + ', '.join(edx_components.__all__) +
          '\nfrom code/functions:\n' + ', '.join(functions.__all__))

    holoviews.notebook_extension('matplotlib')
    holoviews.plotting.mpl.MPLPlot.fig_rcparams['text.usetex'] = True

    # Set plot style.
    options = Store.options(backend='matplotlib')
    options.Contours = Options('style', linewidth=2, color='k')
    options.Contours = Options('plot', aspect='square')
    options.HLine = Options('style', linestyle='--', color='b', linewidth=2)
    options.VLine = Options('style', linestyle='--', color='r', linewidth=2)
    options.Image = Options('style', cmap='RdBu_r')
    options.Image = Options('plot', title_format='{label}')
    options.Path = Options('style', linewidth=1.2, color='k')
    options.Path = Options('plot', aspect='square', title_format='{label}')
    options.Curve = Options('style', linewidth=2, color='k')
    options.Curve = Options('plot', aspect='square', title_format='{label}')
    options.Overlay = Options('plot',
                              show_legend=False,
                              title_format='{label}')
    options.Layout = Options('plot', title_format='{label}')
    options.Surface = Options('style',
                              cmap='RdBu_r',
                              rstride=1,
                              cstride=1,
                              lw=0.2)
    options.Surface = Options('plot', azimuth=20, elevation=8)

    # Turn off a bogus holoviews warning.
    # Temporary solution to ignore the warnings
    warnings.filterwarnings('ignore', r'All-NaN (slice|axis) encountered')

    module_dir = os.path.dirname(__file__)
    matplotlib.rc_file(os.path.join(module_dir, "matplotlibrc"))

    np.set_printoptions(precision=2,
                        suppress=True,
                        formatter={'complexfloat': pretty_fmt_complex})

    # In order to make the notebooks readable through nbviewer we want to hide
    # the code by default. However the same code is executed by the students,
    # and in that case we don't want to hide the code. So we check if the code
    # is executed by one of the mooc developers. Here we do by simply checking
    # for some files that belong to the internal mooc repository, but are not
    # published.  This is a temporary solution, and should be improved in the
    # long run.

    developer = os.path.exists(
        os.path.join(module_dir, os.path.pardir, 'scripts'))

    display_html(
        display.HTML(nb_html_header +
                     (hide_outside_ipython if developer else '')))

    # Patch a bug in holoviews
    from patch_holoviews import patch_all
    patch_all()
示例#52
0
 def tearDown(self):
     Store.options(val=self.store_copy)
     super(TestStoreInheritance, self).tearDown()
示例#53
0
 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()
示例#54
0
 def tearDown(self):
     Store.options(val=self.original_options)
示例#55
0
 def tearDown(self):
     Store.options(val=self.store_copy)
     Store._custom_options = {k: {} for k in Store._custom_options.keys()}
     super(TestXarrayTitle, self).tearDown()
示例#56
0
 def tearDown(self):
     Store.options(val=self.store_mpl, backend='matplotlib')
     Store.options(val=self.store_bokeh, backend='bokeh')
     Store.current_backend = 'matplotlib'
     super(TestCrossBackendOptions, self).tearDown()
示例#57
0
 def tearDown(self):
     Options._option_groups = ['style', 'plot', 'norm']
     Store.options(val=self.original_options)
     Store._custom_options = {k: {} for k in Store._custom_options.keys()}