def make_plot(xname, yname, xax=False, yax=False): mbl = 40 if yax else 0 mbb = 40 if xax else 0 plot = Plot( x_range=xdr, y_range=ydr, background_fill_color="#efe8e2", border_fill_color='white', plot_width=200 + mbl, plot_height=200 + mbb, min_border_left=2+mbl, min_border_right=2, min_border_top=2, min_border_bottom=2+mbb) circle = Circle(x=xname, y=yname, fill_color="color", fill_alpha=0.2, size=4, line_color="color") r = plot.add_glyph(source, circle) xdr.renderers.append(r) ydr.renderers.append(r) xticker = BasicTicker() if xax: xaxis = LinearAxis() xaxis.axis_label = xname plot.add_layout(xaxis, 'below') xticker = xaxis.ticker plot.add_layout(Grid(dimension=0, ticker=xticker)) yticker = BasicTicker() if yax: yaxis = LinearAxis() yaxis.axis_label = yname yaxis.major_label_orientation = 'vertical' plot.add_layout(yaxis, 'left') yticker = yaxis.ticker plot.add_layout(Grid(dimension=1, ticker=yticker)) plot.add_tools(PanTool(), WheelZoomTool()) return plot
def make_plot(xname, yname, xax=False, yax=False): mbl = 40 if yax else 0 mbb = 40 if xax else 0 plot = Plot( x_range=xdr, y_range=ydr, background_fill_color="#efe8e2", border_fill_color='white', plot_width=200 + mbl, plot_height=200 + mbb, min_border_left=2+mbl, min_border_right=2, min_border_top=2, min_border_bottom=2+mbb) circle = Circle(x=xname, y=yname, fill_color="color", fill_alpha=0.2, size=4, line_color="color") r = plot.add_glyph(source, circle) xdr.renderers.append(r) ydr.renderers.append(r) xticker = BasicTicker() if xax: xaxis = LinearAxis() xaxis.axis_label = xname plot.add_layout(xaxis, 'below') xticker = xaxis.ticker plot.add_layout(Grid(dimension=0, ticker=xticker)) yticker = BasicTicker() if yax: yaxis = LinearAxis() yaxis.axis_label = yname yaxis.major_label_orientation = 'vertical' plot.add_layout(yaxis, 'left') yticker = yaxis.ticker plot.add_layout(Grid(dimension=1, ticker=yticker)) plot.add_tools(PanTool(), WheelZoomTool()) return plot
def make_scatter(source, data, xname, yname, xax=False, yax=False): # sets range and borders for plot xdr = DataRange1d(bounds=None) ydr = DataRange1d(bounds=None) mbl = 40 if yax else 0 mbb = 40 if xax else 0 plot = figure(x_range=xdr, y_range=ydr, background_fill_color="#efe8e2", border_fill_color='white', plot_width=200 + mbl, plot_height=200 + mbb, min_border_left=2 + mbl, min_border_right=2, min_border_top=2, min_border_bottom=2 + mbb) # plots points circle = Circle(x=xname, y=yname, fill_color="blue", fill_alpha=0.2, size=4, line_color="blue") plot.add_glyph(source, circle) # calculates and plots regression line a, b, mse = make_regression_line(data, xname, yname) mse_mean = mse.mean() print(xname, yname, mse_mean) x = data[xname] plot.line(x, a * x + b, color='red') plot.axis.visible = False # makes axis according to place in matrix xticker = BasicTicker() if xax: xaxis = LinearAxis() xaxis.axis_label = xname plot.add_layout(xaxis, 'below') xticker = xaxis.ticker plot.add_layout(Grid(dimension=0, ticker=xticker)) yticker = BasicTicker() if yax: yaxis = LinearAxis() yaxis.axis_label = yname yaxis.major_label_orientation = 'vertical' plot.add_layout(yaxis, 'left') yticker = yaxis.ticker plot.add_layout(Grid(dimension=1, ticker=yticker)) return plot
def make_dist(data, xname, xax=False, yax=False): # sets ranges and borders for plot xdr = DataRange1d(bounds=None) ydr = DataRange1d(bounds=None) mbl = 40 if yax else 0 mbb = 40 if xax else 0 TOOLS = "hover, save, reset" plot = figure(x_range=xdr, y_range=ydr, tools=TOOLS, x_axis_label="", y_axis_label="", background_fill_color="#E8DDCB", plot_width=200 + mbl, plot_height=200 + mbb, min_border_left=2 + mbl, min_border_right=2, min_border_top=2, min_border_bottom=2 + mbb) # makes histogram measured = data[xname] hist, edges = np.histogram(measured, density=True, bins=50) # plots histogram plot.quad(top=hist, bottom=0, left=edges[:-1], right=edges[1:], fill_color="#036564", line_color="#033649") # makes axis according to place in matrix plot.axis.visible = False xticker = BasicTicker() if xax: xaxis = LinearAxis() xaxis.axis_label = xname plot.add_layout(xaxis, 'below') xticker = xaxis.ticker yticker = BasicTicker() if yax: yaxis = LinearAxis() yaxis.axis_label = xname yaxis.major_label_orientation = 'vertical' plot.add_layout(yaxis, 'left') yticker = yaxis.ticker plot.legend.location = "center_right" plot.legend.background_fill_color = "darkgrey" return plot
def metrix_plot(xname, yname, xax=False, yax=False, xdr=None, ydr=None, source=None): mbl = 40 if yax else 0 mbb = 40 if xax else 0 plot = Plot(x_range=xdr, y_range=ydr, plot_width=200 + mbl, plot_height=200 + mbb, min_border_left=1 + mbl, min_border_right=1, min_border_top=1, min_border_bottom=1 + mbb) circle = Circle(x=xname, y=yname, fill_color="color", size=4, line_color="color") r = plot.add_glyph(source, circle) xdr.renderers.append(r) ydr.renderers.append(r) xticker = BasicTicker() if xax: xaxis = LinearAxis() xaxis.axis_label = xname plot.add_layout(xaxis, 'below') xticker = xaxis.ticker plot.add_layout(Grid(dimension=0, ticker=xticker)) yticker = BasicTicker() if yax: yaxis = LinearAxis() yaxis.axis_label = yname yaxis.major_label_orientation = 'vertical' plot.add_layout(yaxis, 'left') yticker = yaxis.ticker plot.add_layout(Grid(dimension=1, ticker=yticker)) plot.add_tools(PanTool(), WheelZoomTool(), BoxZoomTool(), SaveTool(), ResetTool()) return plot
def show_coeff(data, xname, yname, xax=False, yax=False): # sets ranges and borders of plot xdr = DataRange1d(bounds=None) ydr = DataRange1d(bounds=None) mbl = 40 if yax else 0 mbb = 40 if xax else 0 plot = figure(x_range=xdr, y_range=ydr, background_fill_color="#efe8e2", border_fill_color='white', plot_width=200 + mbl, plot_height=200 + mbb, min_border_left=2 + mbl, min_border_right=2, min_border_top=2, min_border_bottom=2 + mbb) # calculates and plots correlation coefficient measured1 = data[xname] measured2 = data[yname] coeff = np.corrcoef(measured1, measured2) coeff = round(coeff[0][1], 3) plot.text(text_align='center', text_baseline='middle', text=[coeff], text_font_size='35pt', x=0, y=-5) # adjust axes according to place in matrix plot.axis.visible = False xticker = BasicTicker() if xax: xaxis = LinearAxis() xaxis.axis_label = xname plot.add_layout(xaxis, 'below') xticker = xaxis.ticker yticker = BasicTicker() if yax: yaxis = LinearAxis() yaxis.axis_label = yname yaxis.major_label_orientation = 'vertical' plot.add_layout(yaxis, 'left') yticker = yaxis.ticker plot.add_layout(Grid(dimension=0, ticker=xticker)) plot.add_layout(Grid(dimension=1, ticker=yticker)) return plot
def timeline_days_hours(interval_frequency, all_co2_dataframe, sensors_with_anomalies, data, upper_bound, destination_path): times = pd.date_range(start='00:00:00', end='23:55:00', freq=str(interval_frequency) + 'Min').strftime('%H:%M:%S') days = all_co2_dataframe['timestamp'].dt.strftime('%Y-%m-%d').to_list() days = list(dict.fromkeys(days)) timestamp = list(times) for sensor_name in sensors_with_anomalies: all_durations = [] for k in data['anomalies']['anomaly_co2_values'][sensor_name][0]: k = data['anomalies']['anomaly_co2_values'][sensor_name][0].index( k) all_durations.append( int(data['anomalies']['anomaly_co2_values'][sensor_name][0][k] ['duration'])) data['anomalies']['anomaly_co2_values'][sensor_name][0] p = figure(plot_height=500, plot_width=2000, x_range=timestamp, y_range=days, title='Timeline of periods with CO2 levels higher than ' + str(upper_bound) + ' ppm in ' + sensor_name + '\n Based on data for last ' + str(len(days)) + ' days', active_drag=None, toolbar_location=None) p.x_range.range_padding = 0 p.y_range.range_padding = 0 p.title.text_font_size = '15pt' p.xaxis.axis_label_text_font_size = "15pt" p.yaxis.axis_label_text_font_size = "15pt" p.yaxis.major_label_text_font_size = '9pt' p.xaxis.major_label_text_font_size = '5pt' # set x axis to invisible p.xaxis.visible = False # Add custom axis with tickers labels only every 1 hour labels = np.arange(0, 288, 12).tolist() ticker = FixedTicker() ticker.ticks = labels xaxis = LinearAxis(ticker=ticker) xaxis.major_label_orientation = math.pi / 3 p.add_layout(xaxis, 'below') xaxis.major_label_overrides = { 0: '00:00', 12: '01:00', 24: '02:00', 36: '3:00', 48: '04:00', 60: '05:00', 72: '06:00', 84: '07:00', 96: '08:00', 108: '09:00', 120: '10:00', 132: '11:00', 144: '12:00', 156: '13:00', 168: '14:00', 180: '15:00', 192: '16:00', 204: '17:00', 216: '18:00', 228: '19:00', 240: '20:00', 252: '21:00', 264: '22:00', 276: '23:00' } #add anomalies recorded for each day in considered period for i in data['anomalies']['anomaly_co2_values'][sensor_name][0]: i = data['anomalies']['anomaly_co2_values'][sensor_name][0].index( i) x = [] y = [] x.append(data['anomalies']['anomaly_co2_values'][sensor_name][0][i] ['anomalies_details'][0][0][11:]) x.append(data['anomalies']['anomaly_co2_values'][sensor_name][0][i] ['anomalies_details'][-1][0][11:]) y.append(data['anomalies']['anomaly_co2_values'][sensor_name][0][i] ['anomalies_details'][0][0][0:10]) y.append(data['anomalies']['anomaly_co2_values'][sensor_name][0][i] ['anomalies_details'][-1][0][0:10]) if data['anomalies']['anomaly_co2_values'][sensor_name][0][i][ 'anomalies_details'][0][0][0:10] == data['anomalies'][ 'anomaly_co2_values'][sensor_name][0][i][ 'anomalies_details'][-1][0][0:10]: # print('yes') p.line(x, y, line_width=2, color='blue', legend_label='CO2 above critical value') p.circle(x, y, fill_color="blue", line_color='blue', size=5) else: x1 = x.copy() y1 = y.copy() x2 = x.copy() y2 = y.copy() x1[-1] = times[-1] y1[-1] = y1[0] p.line(x1, y1, line_width=2, color='blue') x2[0] = times[0] y2[0] = y2[-1] p.line(x2, y2, line_width=2, color='blue') x3 = [x1[0], x2[-1]] y3 = [y1[0], y2[-1]] p.circle(x3, y3, fill_color="blue", line_color='blue', size=5) #save graph in output location output_file(destination_path + '/anomalies_timeline_' + sensor_name + '.html') save(p) return p
def generate_performance_plot(hds, hcols): aux_cols = ['Model', "Number_of_Drives", "Percent_of_Drives", "Color"] cols = ['Failure_Rate', 'Capacity', 'Interface', 'Cache', 'RPM', 'Price_GB'] data = {} for c in cols: #print('col: ', c) data[c] = hds[c] for c in aux_cols: #print('col: ', c) data[c] = hds[c] max_scale = 1.0 min_scale = 0.0 max_cache = np.max(hds["Cache"]) min_cache = np.min(hds["Cache"]) cache = ( (max_scale - min_scale) /(max_cache - min_cache))*(hds["Cache"] - max_cache) + max_scale max_rpm = np.max(hds["RPM"]) min_rpm = np.min(hds["RPM"]) rpm = ( (max_scale - min_scale) /(max_rpm - min_rpm))*(hds["RPM"] - max_rpm) + max_scale max_interface = np.max(hds["Interface"]) min_interface = np.min(hds["Interface"]) interface = ( (max_scale - min_scale) /(max_interface - min_interface))*(hds["Interface"] - max_interface) + max_scale performance = interface + rpm + cache max_performance = np.max(performance) min_performance = np.min(performance) performance = ( (max_scale - min_scale) /(max_performance - min_performance))*(performance - max_performance) + max_scale max_failure = np.max(hds["Failure_Rate"]) min_failure = np.min(hds["Failure_Rate"]) reliability = ( (max_scale - min_scale) /(max_failure - min_failure))*(hds["Failure_Rate"] - max_failure) + max_scale reliability = 1.0 - reliability max_cost = np.max(hds["Price_GB"]) min_cost = np.min(hds["Price_GB"]) cost = ( (max_scale - min_scale) /(max_cost-min_cost))*(hds["Price_GB"]-max_cost) + max_scale cost = 1.0 - cost slider_start = .5 data["x"] = np.arange(0,len(hds['Model']),1) data["y"] = slider_start * cost + slider_start * performance + slider_start * reliability data["Cost"] = slider_start * cost data["Performance"] = slider_start * performance data["Reliability"] = slider_start * reliability sizes = list(range(6, 24, 4)) groups = pd.cut(hds["Capacity"].values, len(sizes)) sz = [sizes[i] for i in groups.codes] data["Size"] = sz static_data = {} static_data["Cost"] = cost static_data["Performance"] = performance static_data["Reliability"] = reliability _source = ColumnDataSource(data=data) _static_source = ColumnDataSource(data=static_data) title = "Relative Hard Drive Value" plot = figure(title=title, x_axis_location='below', y_axis_location='left', tools=['hover','save']) hover = plot.select(dict(type=HoverTool)) hover.tooltips = [ ("Model ", "@Model"), ("Failure Rate ", "@Failure_Rate"), (hcols["Capacity"], "@Capacity"), (hcols["Interface"], "@Interface"), (hcols["RPM"], "@RPM"), (hcols["Cache"], "@Cache"), (hcols["Price_GB"], "@Price_GB{1.11}") ] p1 = plot.circle('x', 'y', source = _source, size='Size', color="Color")#, line_color="white", alpha=0.6, hover_color='white', hover_alpha=0.5) from bokeh.models import FuncTickFormatter#, FixedTickFormatter label_dict = {} for i, s in enumerate(hds["Model"]): label_dict[i] = s plot.y_range = Range1d(-.1, 3.1) plot.toolbar.logo = None plot.xaxis.visible = False plot.yaxis.visible = False from bokeh.models import SingleIntervalTicker ticker = SingleIntervalTicker(interval=1, num_minor_ticks=0) xaxis = LinearAxis(axis_label="Model", ticker=ticker) #yaxis = LinearAxis()#axis_label="Relative Merit") xaxis.formatter = FuncTickFormatter(code=""" var labels = %s; return labels[tick]; """ % label_dict) xaxis.major_label_orientation = -np.pi/2.7 plot.add_layout(xaxis, 'below') #plot.add_layout(yaxis, 'left') callback1 = CustomJS(args=dict(source=_source, static_source=_static_source), code=""" var data = source.get("data"); var static_data = static_source.get("data"); var f = cb_obj.value y = data['y'] reli = data['Reliability'] perf = data['Performance'] cost = data['Cost'] static_cost = static_data['Cost'] for (i = 0; i < y.length; i++) { cost[i] = f * static_cost[i] y[i] = reli[i] + cost[i] + perf[i] } source.trigger('change'); """) callback2 = CustomJS(args=dict(source=_source, static_source=_static_source), code=""" var data = source.get("data"); var static_data = static_source.get("data"); var f = cb_obj.value y = data['y'] reli = data['Reliability'] static_reli = static_data['Reliability'] perf = data['Performance'] cost = data['Cost'] for (i = 0; i < y.length; i++) { reli[i] = f * static_reli[i] y[i] = reli[i] + cost[i] + perf[i] } source.trigger('change'); """) callback3 = CustomJS(args=dict(source=_source, static_source=_static_source), code=""" var data = source.get("data"); static_data = static_source.get("data"); var f = cb_obj.value y = data['y'] reli = data['Reliability'] perf = data['Performance'] static_perf = static_data['Performance'] cost = data['Cost'] for (i = 0; i < y.length; i++) { perf[i] = f*static_perf[i] y[i] = reli[i] + cost[i] + perf[i] } source.trigger('change'); """) plot.min_border_left = 0 plot.xaxis.axis_line_width = 2 plot.yaxis.axis_line_width = 2 plot.title.text_font_size = '16pt' plot.xaxis.axis_label_text_font_size = "14pt" plot.xaxis.major_label_text_font_size = "14pt" plot.yaxis.axis_label_text_font_size = "14pt" plot.yaxis.major_label_text_font_size = "14pt" plot.ygrid.grid_line_color = None plot.xgrid.grid_line_color = None plot.toolbar.logo = None plot.outline_line_width = 0 plot.outline_line_color = "white" slider1 = Slider(start=0.0, end=1.0, value=slider_start, step=.05, title="Price") slider2 = Slider(start=0.0, end=1.0, value=slider_start, step=.05, title="Reliability") slider3 = Slider(start=0.0, end=1.0, value=slider_start, step=.05, title="Performance") slider1.js_on_change('value', callback1) slider2.js_on_change('value', callback2) slider3.js_on_change('value', callback3) controls = widgetbox([slider1, slider2,slider3], width=200) layout = row(controls, plot) return layout