def test_plotly_static(self): """Should create a static Plotly plot""" trace = dict(type='scatter', x=[1, 2, 3, 4, 5], y=[1, 2, 3, 4, 5]) result = render.plotly([trace], {}, static=True) self.assertLess(0, result.index('"staticPlot": true'))
def test_plotly_static(self): """Should create a static Plotly plot""" trace = dict( type='scatter', x=[1,2,3,4,5], y=[1,2,3,4,5] ) result = render.plotly([trace], {}, static=True) self.assertLess(0, result.index('"staticPlot": true'))
def test_plotly_import_error(self): """ should fail if unable to import with plotly """ real_import = builtins.__import__ def fake_import(*args, **kwargs): if args and args[0] == 'plotly': raise ImportError('Fake Error') return real_import(*args, **kwargs) with patch('builtins.__import__') as import_func: import_func.side_effect = fake_import result = render.plotly([], {}) self.assertGreater(result.find('cd-ImportError'), 0)
def test_plotly_import_error(self): """Should fail if unable to import with plotly""" real_import = builtins.__import__ def fake_import(*args, **kwargs): if args and args[0] == 'plotly': raise ImportError('Fake Error') return real_import(*args, **kwargs) with patch('builtins.__import__') as import_func: import_func.side_effect = fake_import result = render.plotly([], {}) self.assertGreater(result.find('cd-ImportError'), 0)
def plotly( data: typing.Union[dict, list] = None, layout: dict = None, scale: float = 0.5, figure: dict = None, static: bool = False ): """ Creates a Plotly plot in the display with the specified data and layout. :param data: The Plotly trace data to be plotted. :param layout: The layout data used for the plot. :param scale: The display scale with units of fractional screen height. A value of 0.5 constrains the output to a maximum height equal to half the height of browser window when viewed. Values below 1.0 are usually recommended so the entire output can be viewed without scrolling. :param figure: In cases where you need to create a figure instead of separate data and layout information, you can pass the figure here and leave the data and layout values as None. :param static: If true, the plot will be created without interactivity. This is useful if you have a lot of plots in your notebook. """ r = _get_report() if not figure and not isinstance(data, (list, tuple)): data = [data] if 'plotly' not in r.library_includes: r.library_includes.append('plotly') r.append_body(render.plotly( data=data, layout=layout, scale=scale, figure=figure, static=static )) r.stdout_interceptor.write_source('[ADDED] Plotly plot\n')
def plotly( data: typing.Union[dict, list] = None, layout: dict = None, scale: float = 0.5, figure: dict = None, static: bool = False ): """ Creates a Plotly plot in the display with the specified data and layout :param data: The Plotly trace data to be plotted :param layout: The layout data used for the plot :param scale: The display scale with units of fractional screen height. A value of 0.5 constrains the output to a maximum height equal to half the height of browser window when viewed. Values below 1.0 are usually recommended so the entire output can be viewed without scrolling. :param figure: In cases where you need to create a figure instead of separate data and layout information, you can pass the figure here and leave the data and layout values as None. :param static: If true, the plot will be created without interactivity. This is useful if you have a lot of plots in your notebook. """ r = _get_report() if not figure and not isinstance(data, (list, tuple)): data = [data] if 'plotly' not in r.library_includes: r.library_includes.append('plotly') r.append_body(render.plotly( data=data, layout=layout, scale=scale, figure=figure, static=static ))