def plot(self): """ Returns a hvPlot object to provide a high-level plotting API. To display in a notebook, be sure to run ``intake.output_notebook()`` first. Adapted from the original code to be able to plot the data stored in the twiss table files. """ try: from hvplot import hvPlot except ImportError: raise ImportError( "The intake plotting API requires hvplot." "hvplot may be installed with:\n\n" "`conda install -c pyviz hvplot` or " "`pip install hvplot`." ) metadata = self.metadata.get("plot", {}) # print("hvplot meta", metadata) # fields = self.metadata.get("fields", {}) # print("hv fields", fields) # for attrs in fields.values(): # if 'range' in attrs: # attrs['range'] = tuple(attrs['range']) # metadata['fields'] = fields plots = self.metadata.get("plots", {}) self._load_metadata() # print(hvPlot(self.twiss, custom_plots=plots, **metadata)) return hvPlot(self.twiss, custom_plots=plots, **metadata)
def test_define_customize_method(self): hvplot = hvPlot(self.df, {'scatter': {'width': 42, 'height': 42}}) custom_scatter = hvplot.scatter(y='y') curve = hvplot.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)
def plot(self): """ Shamelessly copied from the amazing Intake package and modified slightly. Returns a hvPlot object to provide a high-level plotting API. Will use Dask if available, reading parralelism is set by page size and then data is repartitioned by number of cpus available. small collections are pre-read and converted to regular pandas dataframe. To display in a notebook, be sure to run ``panel_eve.output_notebook()`` first. """ if not self.is_tabular: raise TypeError( "Plotting API currently only supports tabular data.") if self._plot is None: try: from hvplot import hvPlot except ImportError: raise ImportError("The eve_panel plotting API requires hvplot." "hvplot may be installed with:\n\n" "`conda install -c pyviz hvplot` or " "`pip install hvplot`.") nitems = self.nitems if nitems < self.items_per_page: data = self.df else: try: import dask persist = (nitems / self.items_per_page) < mp.cpu_count() data = self.to_dask(persist=persist) data = data.repartition( npartitions=min(data.npartitions, mp.cpu_count())) if persist and nitems < 1e4: data = data.compute() except ImportError: data = self.df metadata = self.metadata.get('plot', {}) fields = self.metadata.get('fields', {}) for attrs in fields.values(): if 'range' in attrs: attrs['range'] = tuple(attrs['range']) metadata['fields'] = fields plots = self.metadata.get('plots', {}) self._plot = hvPlot(data, custom_plots=plots, **metadata) return self._plot
def draw(self, *args): """Recreate the plot with current arguments Called by "Plot" button """ kwargs = self.control.kwargs kwargs['kind'] = self.method.value self.kwtext.object = pretty_describe(kwargs) data = self.control.sample.sample_data(self.data) self._plot = hvPlot(data)(**kwargs) self.output[0] = pn.Row(*pn.pane.HoloViews(self._plot), name='Plot') fig = list(self.output[0][0]._models.values())[0][0] try: xrange = fig.x_range.start, fig.x_range.end yrange = fig.y_range.start, fig.y_range.end self.control.set_ranges(xrange, yrange) except AttributeError: # some plots (e.g., Table) don't have ranges pass
def plot(self): """ Returns a hvPlot object to provide a high-level plotting API. To display in a notebook, be sure to run ``intake.output_notebook()`` first. """ try: from hvplot import hvPlot except ImportError: raise ImportError("The intake plotting API requires hvplot." "hvplot may be installed with:\n\n" "`conda install -c pyviz hvplot` or " "`pip install hvplot`.") metadata = self.metadata.get('plot', {}) fields = self.metadata.get('fields', {}) for attrs in fields.values(): if 'range' in attrs: attrs['range'] = tuple(attrs['range']) metadata['fields'] = fields plots = self.metadata.get('plots', {}) return hvPlot(self, custom_plots=plots, **metadata)
def draw(self, *args): kwargs = self.control.kwargs kwargs['kind'] = self.method.value print(kwargs) self._plot = hvPlot(self.data)(**kwargs) self.output[0] = pn.pane.HoloViews(self._plot)
def test_attempt_to_override_kind_on_method(self): hvplot = hvPlot(self.df, {'scatter': {'kind': 'line'}}) self.assertIsInstance(hvplot.scatter(y='y'), Scatter)
def test_define_default_options(self): hvplot = hvPlot(self.df, width=42, height=42) curve = hvplot(y='y') opts = Store.lookup_options('bokeh', curve, 'plot') self.assertEqual(opts.options.get('width'), 42) self.assertEqual(opts.options.get('height'), 42)