def box(self, x, y): if x and y: return hv.BoxWhisker(self.data, kdims=[x], vdims=[y]).opts(plot=self._plot_opts) index = self.data.index.name or 'index' df = self.data.reset_index() df = pd.melt(df, id_vars=[index], var_name='Group', value_name='Value') plot_opts = dict(self._plot_opts) plot_opts['invert_axes'] = not self.kwds.get('vert', True) return hv.BoxWhisker(df, kdims=['Group'], vdims=['Value']).opts(plot=plot_opts)
def plot_boxwhiskers(df): title = "Áramtermelés eloszlása zónánként" boxwhisker = hv.BoxWhisker(df, ('ZONEID', 'Zóna'), ('POWER', 'Teljesítmény'), label=title) boxwhisker.options(show_legend=False, width=500, height=500) title2 = "Áramtermelés eloszlása óránként csoportosítva" boxwhisker2 = hv.BoxWhisker(df, ('HOUR', 'Óra'), ('POWER', 'Teljesítmény'), label=title2) boxwhisker2.options(show_legend=False, width=500, height=500) options = {'BoxWhisker': dict(width=500, height=500)} return (boxwhisker + boxwhisker2).options(options)
def boxInts(data): p1hv = hv.BoxWhisker(data, ['clsLabel'], 'meanInt', label="mean intensity per cluster").sort() p1hv.opts(show_legend=False, width=500, cmap='Set1', ylim=(-1, 40)) # p1hv.opts(show_legend=False, width=500) return p1hv
def boxplot_metrics(data, title, color_by='Method', palette='Set3', invert_xaxis=True): data = data.melt(var_name='Variables', value_name='Metric Value') data['Method'] = data['Variables'].apply(lambda x: x.split('-')[0]) data['Ranking'] = data['Variables'].apply(lambda x: x.split('-')[1]) data['Metric'] = data['Variables'].apply(lambda x: x.split('-')[2]) boxwhisker = hv.BoxWhisker(data, ['Metric', 'Ranking', 'Method'], 'Metric Value', label=title) boxwhisker.opts(show_legend=False, width=900, height=500, box_fill_color=color_by, cmap=palette, ylim=(0, 1), xrotation=45, invert_xaxis=invert_xaxis, toolbar='above') f = hv.render(boxwhisker, backend='bokeh') f.toolbar.logo = None f.grid.grid_line_color = 'lightgrey' f.grid.grid_line_dash = [5, 3] return f
def create_cluster_boxplot(x_corpus: VectorizedCorpus, token_clusters: pd.DataFrame, n_cluster: int, color: str) -> hv.opts: xs = np.arange(x_corpus.document_index.year.min(), x_corpus.document_index.year.max() + 1, 1) token_ids = list( token_clusters[token_clusters.cluster == n_cluster].index) Y = x_corpus.data[:, token_ids] xsr = np.repeat(xs, Y.shape[1]) ysr = Y.ravel() data = pd.DataFrame(data={'year': xsr, 'frequency': ysr}) violin: hv.BoxWhisker = hv.BoxWhisker(data, ('year', 'Year'), ('frequency', 'Frequency')) violin_opts = { 'height': 600, 'width': 900, 'box_fill_color': color, 'xrotation': 90, # 'violin_width': 0.8 } return violin.opts(**violin_opts)
def BoxWhisker(dfs, measurement, configs, analysisType, **addConfigs): """Plots a measurement from all df as boxwisker""" newConfigs = addConfigs log.info("Generating BoxWhisker Plot for {}".format(measurement)) try: plot = hv.BoxWhisker( dfs["All"], kdims="Name", vdims=measurement, label="BoxWhisker: {}".format(measurement), group="BoxWhisker: {}".format(measurement), ) # plot = relabelPlot(plot, label="{}".format(measurement)) # get labels from the configs # ylabel = "{} [{}]".format(measurement, dfs[dfs["keys"][0]]["units"][dfs[dfs["keys"][0]]["measurements"].index(measurement)]) try: ylabel = "{} [{}]".format( measurement, dfs[dfs["keys"][0]]["units"][dfs[ dfs["keys"][0]]["measurements"].index(measurement)], ) except Exception as err: log.error( "Label could not be genereated for concatonated Histogram {}. Error: {}" .format(measurement, err)) ylabel = "X-Axis" plot.opts( box_alpha=0.3, xrotation=80, box_color="blue", height=500, show_legend=False, width=600, whisker_color="blue", ylabel=ylabel, ) # Update the plot specific options if need be generalOptions = configs[analysisType].get("General", {}) newConfigs.update(generalOptions.copy()) data_options = (configs[analysisType].get(measurement, {}).get( "BoxWhisker", {}).get("PlotOptions", {})) newConfigs.update(configs[analysisType].get( "{}Options".format("BoxWhisker"), {})) newConfigs.update(data_options) plot = customize_plot(plot, "", configs[analysisType], **newConfigs) except Exception as err: log.error( "Unexpected error happened during BoxWhisker plot generation {}. Error: {}" .format(measurement, err)) return None return plot
def hv_box(data, label='', style=dict(), side='Successes', width=800, height=400): return hv.BoxWhisker(data, ["Team", "Task"], side, label=label).opts(plot=dict(tools=['hover'], legend_position="top", xrotation=45, width=width, height=height), style=style)
def plot_boxplot_bokeh(df): foo = df.stack().reset_index() foo = foo[[foo.columns[1], 0]] foo.columns = ['group', 'error'] table = hv.Table(foo) hvplot = hv.BoxWhisker(table.data, kdims=['group']) rend = hv.renderer('bokeh') fig = rend.get_plot(hvplot).state fig.plot_width = 600 fig.plot_height = 500 fig.xaxis.major_label_orientation = 45 fig.grid.grid_line_alpha = 0.5 fig.background_fill_color = 'beige' fig.background_fill_alpha = 0.2 return fig
def boxplot_times(time_results): aux = ['1', '0.9', '0.8', '0.7', '0.6', '0.5', '0.4', '0.3', '0.2', '0.1'] aux.reverse() time_results.columns = aux medias = np.mean(time_results) prueba = time_results.melt() box_times = hv.BoxWhisker( prueba, 'variable', 'value', label='Execution time for different number of edges') times_plot = hv.Curve((aux, medias)).opts(color='red', width=400) box_times = box_times.redim.label(variable='Percentage of the total edges', value='Time (s)') times_plot = times_plot.redim.label(x='Percentaje of the total edges') return box_times * times_plot
def NeoRecoScatter(self): # # A vs R colored by RecoPo # p = figure(height=400) # p.circle(x=x,y=y, size=3, color="navy", alpha=0.5) out = self.recopoData.loc[ self.recopoData.NeoantigenRecognitionPotential != 0.0].copy() # out.NeoantigenRecognitionPotential = np.log10(out.NeoantigenRecognitionPotential) p = hv.BoxWhisker(out, 'Sample', 'NeoantigenRecognitionPotential') p.opts(logy=True, xrotation=90, height=200, box_fill_color='Sample', show_legend=False, cmap='Category20') # p.opts(style=dict(box_color=hv.Cycle('Set1'))) o = hv.render(p) return (o)
def cpu_box(data): return hv.BoxWhisker(data, 'CPU', 'Utilization').relabel('CPU Usage')
]) TOOLS_rhat = [ "save", "pan", "reset", hover_tool_rhat, "ybox_zoom", "ywheel_zoom" ] TOOLS_ess = [ "save", "pan", "reset", hover_tool_ess, "ybox_zoom", "ywheel_zoom" ] TOOLS_mcse = ["save", "pan", "reset", hover_tool, "ybox_zoom", "ywheel_zoom"] title = f"rhat accuracy ({datetime.now().date().isoformat()})" boxwhisker = hv.BoxWhisker( comparison[comparison.group == "rhat"].rename(columns={ "diff_min": "diff_min_rhat", "diff": "diff_rhat" }), ["diagnostic", "diff_min_rhat", "diff_max"], ["diff_rhat"], label=title, ) boxwhisker.opts( show_legend=False, width=400, show_grid=True, tools=TOOLS_rhat, default_tools=[], xlabel="", ) title = f"ess ({datetime.now().date().isoformat()})" boxwhisker2 = hv.BoxWhisker(
#*These can easily be created using numpy's histogram function as illustrated below. #The plot is interactive and comes with a bunch of tools. You can customize these tools as well; #for your many options, see http://bokeh.pydata.org/en/latest/docs/user_guide/tools.html. #example from bokeh.io import show import holoviews as hv import numpy as np frequencies, edges = np.histogram(flora['petal width'], bins = 5) hv.Histogram(frequencies, edges, label = 'Histogram') #2. ScatterPlot hv.Scatter(flora[['petal width','sepal length']],label = 'Scatter plot') #3. BoxPlot hv.BoxWhisker(flora['sepal length'], label = "Box whiskers plot") #Mid-level charts: the Plotting interface #Beyond the canned methods above, Bokeh provides a "mid-level" interface that more directly exposes the grammar of graphics methodology for constructing visual displays. #The basic procedure is #Create a blank canvas by calling bokeh.plotting.figure #Add glyphs, which are geometric shapes. #example from bokeh.plotting import figure # Create a canvas with a specific set of tools for the user: TOOLS = 'pan,box_zoom,wheel_zoom,lasso_select,save,reset,help'
def _fcn(key): info = data[key] if info.resolution.mean() < 1e-1: info = info.assign(resolution=data[key].resolution * 1e3) box = hv.BoxWhisker(info, ['trackcount', 'bead'], 'resolution') return box.options(finalize_hooks=[_fhook])
def datafunc_down(data): algo1_data = data['algo-1'] algo2_data = data['algo-2'] return hv.BoxWhisker(algo1_data, vdims='algo-1') + hv.BoxWhisker( algo2_data, vdims='algo-2')