def test_combined_two_types_2(self):
     line = "Layout plot[fig_inches=(3, 3)] Image (string='foo') [foo='bar baz']"
     expected = {
         "Layout": {"plot": Options(fig_inches=(3, 3))},
         "Image": {"style": Options(string="foo"), "plot": Options(foo="bar baz")},
     }
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #2
0
 def test_plot_opts_with_space(self):
     "Space in the tuple, see issue #77"
     line = "Layout [fig_inches=(3, 3) title_format='foo bar']"
     expected= {'Layout':
                {'plot':
                 Options(title_format='foo bar', fig_inches=(3, 3))}}
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #3
0
 def test_combined_1(self):
     line = "Layout plot[fig_inches=(3,3) foo='bar baz'] Layout (string='foo')"
     expected= {'Layout':
                {'plot':
                 Options(foo='bar baz', fig_inches=(3, 3)),
                 'style': Options(string='foo')}}
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #4
0
 def test_style_opts_intermediate_explicit(self):
     line = "Layout style(string='foo' test=3, b=True )"
     expected= {'Layout':{
                 'style': Options(string='foo',
                                  test=3,
                                  b=True)}}
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #5
0
 def test_plot_opts_with_space_explicit(self):
     line = "Layout plot[fig_inches=(3, 3) title_format='foo bar']"
     expected = {
         'Layout': {
             'plot': Options(title_format='foo bar', fig_inches=(3, 3))
         }
     }
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #6
0
 def test_norm_opts_simple_1(self):
     line = "Layout {+axiswise}"
     expected = {
         'Layout': {
             'norm': Options(axiswise=True, framewise=False)
         }
     }
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #7
0
 def test_style_opts_cycle_list(self):
     line = "Curve (color=Cycle(values=['r', 'g', 'b']))"
     expected = {
         'Curve': {
             'style': Options(color=Cycle(values=['r', 'g', 'b']))
         }
     }
     self.assertEqual(OptsSpec.parse(line, {'Cycle': Cycle}), expected)
Beispiel #8
0
 def test_style_opts_advanced(self):
     line = "Layout (string='foo' test=3, b=True color=Cycle(values=[1,2]))"
     expected= {'Layout':{
                 'style': Options(string='foo',
                                  test=3,
                                  b=True,
                                  color=Cycle(values=[1,2]))}}
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #9
0
 def test_combined_two_types_2(self):
     line = "Layout plot[fig_inches=(3, 3)] Image (string='foo') [foo='bar baz']"
     expected= {'Layout':
                {'plot':
                 Options(fig_inches=(3, 3))},
                'Image': {
                    'style': Options(string='foo'),
                    'plot': Options(foo='bar baz')}}
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #10
0
 def test_combined_1(self):
     line = "Layout plot[fig_inches=(3,3) foo='bar baz'] Layout (string='foo')"
     expected = {
         'Layout': {
             'plot': Options(foo='bar baz', fig_inches=(3, 3)),
             'style': Options(string='foo')
         }
     }
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #11
0
 def test_plot_opts_with_space(self):
     "Space in the tuple, see issue #77"
     line = "Layout [fig_inches=(3, 3) title_format='foo bar']"
     expected = {
         'Layout': {
             'plot': Options(title_format='foo bar', fig_inches=(3, 3))
         }
     }
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #12
0
 def test_plot_opts_multiple_paths(self):
     line = "Image Curve [fig_inches=(3, 3) title_format='foo bar']"
     expected = {
         'Image': {
             'plot': Options(title_format='foo bar', fig_inches=(3, 3))
         },
         'Curve': {
             'plot': Options(title_format='foo bar', fig_inches=(3, 3))
         }
     }
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #13
0
 def test_plot_opts_dict_without_space(self):
     line = "Curve [fontsize=dict(xlabel=10,title=20)]"
     expected = {
         'Curve': {
             'plot': Options(fontsize={
                 'xlabel': 10,
                 'title': 20
             })
         }
     }
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #14
0
 def test_norm_opts_multiple_paths(self):
     line = "Image Curve {+axiswise +framewise}"
     expected = {
         'Image': {
             'norm': Options(axiswise=True, framewise=True)
         },
         'Curve': {
             'norm': Options(axiswise=True, framewise=True)
         }
     }
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #15
0
 def test_style_opts_multiple_paths(self):
     line = "Image Curve (color='beautiful')"
     expected = {
         'Image': {
             'style': Options(color='beautiful')
         },
         'Curve': {
             'style': Options(color='beautiful')
         }
     }
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #16
0
 def test_style_opts_dict_without_space(self):
     line = "Curve (fontsize={'xlabel': 10,'title': 20})"
     expected = {
         'Curve': {
             'style': Options(fontsize={
                 'xlabel': 10,
                 'title': 20
             })
         }
     }
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #17
0
 def test_combined_two_types_2(self):
     line = "Layout plot[fig_inches=(3, 3)] Image (string='foo') [foo='bar baz']"
     expected = {
         'Layout': {
             'plot': Options(fig_inches=(3, 3))
         },
         'Image': {
             'style': Options(string='foo'),
             'plot': Options(foo='bar baz')
         }
     }
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #18
0
 def test_style_opts_advanced(self):
     line = "Layout (string='foo' test=3, b=True color=Cycle(values=[1,2]))"
     expected = {
         'Layout': {
             'style':
             Options(string='foo',
                     test=3,
                     b=True,
                     color=Cycle(values=[1, 2]))
         }
     }
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #19
0
 def test_combined_multiple_paths_merge(self):
     line = "Image Curve [fig_inches=(3, 3)] (c='b') Image (s=3)"
     expected = {
         'Image': {
             'plot': Options(fig_inches=(3, 3)),
             'style': Options(c='b', s=3)
         },
         'Curve': {
             'plot': Options(fig_inches=(3, 3)),
             'style': Options(c='b')
         }
     }
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #20
0
    def opts(self, line='', cell=None):
        """
        The opts line/cell magic with tab-completion.

        %%opts [ [path] [normalization] [plotting options] [style options]]+

        path:             A dotted type.group.label specification
                          (e.g. Image.Grayscale.Photo)

        normalization:    List of normalization options delimited by braces.
                          One of | -axiswise | -framewise | +axiswise | +framewise |
                          E.g. { +axiswise +framewise }

        plotting options: List of plotting option keywords delimited by
                          square brackets. E.g. [show_title=False]

        style options:    List of style option keywords delimited by
                          parentheses. E.g. (lw=10 marker='+')

        Note that commas between keywords are optional (not
        recommended) and that keywords must end in '=' without a
        separating space.

        More information may be found in the class docstring of
        ipython.parser.OptsSpec.
        """
        line, cell = self._partition_lines(line, cell)
        try:
            spec = OptsSpec.parse(line, ns=self.shell.user_ns)
        except SyntaxError:
            display(
                HTML(
                    "<b>Invalid syntax</b>: Consult <tt>%%opts?</tt> for more information."
                ))
            return

        if cell:
            self.register_custom_spec(spec)
            # Process_element is invoked when the cell is run.
            self.shell.run_cell(cell, store_history=STORE_HISTORY)
        else:
            try:
                StoreOptions.validate_spec(spec)
            except OptionError as e:
                OptsMagic.error_message = None
                display(HTML(self._format_options_error(e)))
                return

            StoreOptions.apply_customizations(spec, Store.options())
        OptsMagic.error_message = None
Beispiel #21
0
    def opts(self, line='', cell=None):
        """
        The opts line/cell magic with tab-completion.

        %%opts [ [path] [normalization] [plotting options] [style options]]+

        path:             A dotted type.group.label specification
                          (e.g. Image.Grayscale.Photo)

        normalization:    List of normalization options delimited by braces.
                          One of | -axiswise | -framewise | +axiswise | +framewise |
                          E.g. { +axiswise +framewise }

        plotting options: List of plotting option keywords delimited by
                          square brackets. E.g. [show_title=False]

        style options:    List of style option keywords delimited by
                          parentheses. E.g. (lw=10 marker='+')

        Note that commas between keywords are optional (not
        recommended) and that keywords must end in '=' without a
        separating space.

        More information may be found in the class docstring of
        ipython.parser.OptsSpec.
        """
        line, cell = self._partition_lines(line, cell)
        try:
            spec = OptsSpec.parse(line, ns=self.shell.user_ns)
        except SyntaxError:
            display(HTML("<b>Invalid syntax</b>: Consult <tt>%%opts?</tt> for more information."))
            return

        if cell:
            self.register_custom_spec(spec)
            # Process_element is invoked when the cell is run.
            self.shell.run_cell(cell, store_history=STORE_HISTORY)
        else:
            try:
                StoreOptions.validate_spec(spec)
            except OptionError as e:
                OptsMagic.error_message = None
                display(HTML(self._format_options_error(e)))
                return

            StoreOptions.apply_customizations(spec, Store.options())
        OptsMagic.error_message = None
Beispiel #22
0
 def test_combined_multiple_paths(self):
     line = "Image Curve {+framewise} [fig_inches=(3, 3) title_format='foo bar'] (c='b') Layout [string='foo'] Overlay"
     expected = {
         'Image': {
             'norm': Options(framewise=True, axiswise=False),
             'plot': Options(title_format='foo bar', fig_inches=(3, 3)),
             'style': Options(c='b')
         },
         'Curve': {
             'norm': Options(framewise=True, axiswise=False),
             'plot': Options(title_format='foo bar', fig_inches=(3, 3)),
             'style': Options(c='b')
         },
         'Layout': {
             'plot': Options(string='foo')
         },
         'Overlay': {}
     }
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #23
0
    def opts(self, line='', cell=None):
        """
        The opts line/cell magic with tab-completion.

        %%opts [ [path] [normalization] [plotting options] [style options]]+

        path:             A dotted type.group.label specification
                          (e.g. Image.Grayscale.Photo)

        normalization:    List of normalization options delimited by braces.
                          One of | -groupwise | -mapwise | +groupwise | +mapwise |
                          E.g. { -groupwise -mapwise }

        plotting options: List of plotting option keywords delimited by
                          square brackets. E.g. [show_title=False]

        style options:    List of style option keywords delimited by
                          parentheses. E.g. (lw=10 marker='+')

        Note that commas between keywords are optional (not
        recommended) and that keywords must end in '=' without a
        separating space.

        More information may be found in the class docstring of
        ipython.parser.OptsSpec.
        """
        get_object = None
        try:
            spec = OptsSpec.parse(line)
            spec = self.expand_compositor_keys(spec)
        except SyntaxError:
            display(HTML("<b>Invalid syntax</b>: Consult <tt>%%opts?</tt> for more information."))
            return

        self.register_custom_spec(spec, cell is not None)
        if cell:
            self.shell.run_cell(cell, store_history=STORE_HISTORY)
        else:
            retval = self.customize_tree(spec, Store.options)
            if retval is None:
                display(HTML(OptsMagic.error_message))
        OptsMagic.error_message = None
Beispiel #24
0
 def test_style_opts_cycle_function(self):
     # Explicitly compare because list of arrays do not compare correctly
     import numpy as np
     np.random.seed(42)
     line = "Curve (color=Cycle(values=list(np.random.rand(3,3))))"
     options = OptsSpec.parse(line, {'np': np, 'Cycle': Cycle})
     self.assertTrue('Curve' in options)
     self.assertTrue('style' in options['Curve'])
     self.assertTrue('color' in options['Curve']['style'].kwargs)
     self.assertTrue(
         isinstance(options['Curve']['style'].kwargs['color'], Cycle))
     values = np.array([[0.37454012, 0.95071431, 0.73199394],
                        [0.59865848, 0.15601864, 0.15599452],
                        [0.05808361, 0.86617615, 0.60111501]])
     expected = {
         'Curve': {
             'style': Options(color=Cycle(values=list(values)))
         }
     }
     self.assertEqual(
         np.array(options['Curve']['style'].kwargs['color'].values), values)
Beispiel #25
0
 def test_style_opts_simple_explicit(self):
     line = "Layout style(string='foo')"
     expected= {'Layout':{
                 'style': Options(string='foo')}}
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #26
0
 def test_norm_opts_simple_1(self):
     line = "Layout {+axiswise}"
     expected= {'Layout':
                {'norm': Options(axiswise=True, framewise=False)}}
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #27
0
 def test_style_opts_simple_explicit(self):
     line = "Layout style(string='foo')"
     expected = {'Layout': {'style': Options(string='foo')}}
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #28
0
 def test_style_opts_intermediate_explicit(self):
     line = "Layout style(string='foo' test=3, b=True )"
     expected = {'Layout': {'style': Options(string='foo', test=3, b=True)}}
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #29
0
 def test_combined_multiple_paths_merge_precedence(self):
     line = "Image (s=0, c='b') Image (s=3)"
     expected = {'Image': {'style': Options(c='b', s=3)}}
     self.assertEqual(OptsSpec.parse(line), expected)
renderer.save(
    layout,
    'example_IV',
    options={'Image': {
        'plot': dict(fig_size=150),
        'style': dict(cmap='jet')
    }})

# Example V: Specify the style using the %opts magic syntax
#             without IPython (requires pyparsing)

from holoviews.ipython.parser import OptsSpec

renderer.save(image + waves,
              'example_V',
              options=OptsSpec.parse("Image (cmap='gray')"))

#=================================================#
# Style II: Creating objects with specific styles #
#=================================================#

# Create a renderer that will save to PNG
renderer = Store.renderers['matplotlib'].instance(fig='png')

# Example I: Save the default Layout
renderer.save(layout, 'initial_layout')

# Example II: Explicitly build a new Layout with a new, customized Image
renderer.save(image(style={'cmap': 'Blues'}) + curve, 'recomposed_layout')

# Example III:  Note that the original layout and image are untouched.
Beispiel #31
0
 def test_plot_opts_nested_brackets(self):
     line = "Curve [title_format=', '.join(('A', 'B'))]"
     expected = {'Curve': {'plot': Options(title_format='A, B')}}
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #32
0
 def test_plot_opts_with_space_explicit(self):
     line = "Layout plot[fig_inches=(3, 3) title_format='foo bar']"
     expected = {"Layout": {"plot": Options(title_format="foo bar", fig_inches=(3, 3))}}
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #33
0
 def test_style_opts_simple_explicit(self):
     line = "Layout style(string='foo')"
     expected = {"Layout": {"style": Options(string="foo")}}
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #34
0
 def test_plot_opts_simple_explicit(self):
     line = "Layout plot[fig_inches=(3,3) title_format='foo bar']"
     expected= {'Layout':
                {'plot':
                 Options(title_format='foo bar', fig_inches=(3, 3))}}
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #35
0
 def test_combined_1(self):
     line = "Layout plot[fig_inches=(3,3) foo='bar baz'] Layout (string='foo')"
     expected = {"Layout": {"plot": Options(foo="bar baz", fig_inches=(3, 3)), "style": Options(string="foo")}}
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #36
0
 def test_norm_opts_simple_explicit_2(self):
     line = "Layout norm{+axiswise +framewise}"
     expected = {"Layout": {"norm": Options(axiswise=True, framewise=True)}}
     self.assertEqual(OptsSpec.parse(line), expected)
Beispiel #37
0
 def test_style_opts_intermediate(self):
     line = "Layout (string='foo' test=3, b=True)"
     expected = {"Layout": {"style": Options(string="foo", test=3, b=True)}}
     self.assertEqual(OptsSpec.parse(line), expected)