Python plotly.graph_objs.Layout() Examples
The following are 30
code examples of plotly.graph_objs.Layout().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
plotly.graph_objs
, or try the search function
.
Example #1
Source File: callret_analysis.py From idasec with GNU Lesser General Public License v2.1 | 7 votes |
def generate_chart(self, _): try: import plotly import plotly.graph_objs as go data = [[0, 0, 0], [0, 0, 0]] ok, viol = self.results.get_ok_viol() x = ["OK (%d)" % ok, "Tampering (%d)" % viol] for ret in self.results: i = 1 if ret.is_tampering() else 0 data[i][0] += ret.is_aligned() data[i][1] += ret.is_disaligned() data[i][2] += ret.is_single() final_data = [go.Bar(x=x, y=[x[0] for x in data], name="Aligned"), go.Bar(x=x, y=[x[1] for x in data], name="Disaligned"), go.Bar(x=x, y=[x[2] for x in data], name="Single")] fig = go.Figure(data=final_data, layout=go.Layout(barmode='group', title='Call stack tampering labels')) plotly.offline.plot(fig, output_type='file', include_plotlyjs=True, auto_open=True) except ImportError: self.log("ERROR", "Plotly module not available")
Example #2
Source File: draw.py From textprep with MIT License | 7 votes |
def _draw_scatter(all_vocabs, all_freqs, output_prefix): colors = [(s and t) and (s < t and s / t or t / s) or 0 for s, t in all_freqs] colors = [c and np.log(c) or 0 for c in colors] trace = go.Scattergl( x=[s for s, t in all_freqs], y=[t for s, t in all_freqs], mode='markers', text=all_vocabs, marker=dict(color=colors, showscale=True, colorscale='Viridis')) layout = go.Layout( title='Scatter plot of shared tokens', hovermode='closest', xaxis=dict(title='src freq', type='log', autorange=True), yaxis=dict(title='trg freq', type='log', autorange=True)) fig = go.Figure(data=[trace], layout=layout) py.plot( fig, filename='{}_scatter.html'.format(output_prefix), auto_open=False)
Example #3
Source File: nanoplotter_main.py From NanoPlot with GNU General Public License v3.0 | 6 votes |
def plotly_histogram(array, color="#4CB391", title=None, xlabel=None, ylabel=None): data = [go.Histogram(x=array, opacity=0.4, marker=dict(color=color))] html = plotly.offline.plot( {"data": data, "layout": go.Layout(barmode='overlay', title=title, yaxis_title=ylabel, xaxis_title=xlabel)}, output_type="div", show_link=False) fig = go.Figure( {"data": data, "layout": go.Layout(barmode='overlay', title=title)}) return html, fig
Example #4
Source File: test_vis.py From IRCLogParser with GNU General Public License v3.0 | 6 votes |
def test_generate_group_bar_charts(self, mock_py): x_values = [ [5.10114882, 5.0194652482, 4.9908093076], [4.5824497358, 4.7083614037, 4.3812775722], [2.6839471308, 3.0441476209, 3.6403820447] ] y_values = ['#kubuntu-devel', '#ubuntu-devel', '#kubuntu'] trace_headers = ['head1', 'head2', 'head3'] test_data = [ go.Bar( x=x_values, y=y_values[i], name=trace_headers[i] ) for i in range(len(y_values)) ] layout = go.Layout(barmode='group') fig = go.Figure(data=test_data, layout=layout) vis.generate_group_bar_charts(y_values, x_values, trace_headers, self.test_data_dir, 'test_group_bar_chart') self.assertEqual(mock_py.call_count, 1) self.assertEqual(fig.get('data')[0], mock_py.call_args[0][0].get('data')[0])
Example #5
Source File: heating_reset_schedule.py From CityEnergyAnalyst with MIT License | 6 votes |
def heating_reset_schedule(data_frame, analysis_fields, title, output_path): # CREATE FIRST PAGE WITH TIMESERIES traces = [] x = data_frame["T_ext_C"].values data_frame = data_frame.replace(0, np.nan) for field in analysis_fields: y = data_frame[field].values name = NAMING[field] trace = go.Scattergl(x=x, y=y, name=name, mode='markers', marker=dict(color=COLOR[field])) traces.append(trace) layout = go.Layout(images=LOGO, title=title, xaxis=dict(title='Outdoor Temperature [C]'), yaxis=dict(title='HVAC System Temperature [C]')) fig = go.Figure(data=traces, layout=layout) plot(fig, auto_open=False, filename=output_path) return {'data': traces, 'layout': layout}
Example #6
Source File: peak_load.py From CityEnergyAnalyst with MIT License | 6 votes |
def peak_load_district(data_frame_totals, analysis_fields, title, output_path): traces = [] data_frame_totals['total'] = data_frame_totals[analysis_fields].sum(axis=1) data_frame_totals = data_frame_totals.sort_values(by='total', ascending=False) # this will get the maximum value to the left for field in analysis_fields: y = data_frame_totals[field] total_perc = (y / data_frame_totals['total'] * 100).round(2).values total_perc_txt = ["(" + str(x) + " %)" for x in total_perc] name = NAMING[field] trace = go.Bar(x=data_frame_totals["Name"], y=y, name=name, marker=dict(color=COLOR[field])) traces.append(trace) layout = go.Layout(title=title, barmode='group', yaxis=dict(title='Peak Load [kW]'), showlegend=True) fig = go.Figure(data=traces, layout=layout) plot(fig, auto_open=False, filename=output_path) return {'data': traces, 'layout': layout}
Example #7
Source File: main.py From deep_architect with MIT License | 6 votes |
def make_layout(xkey, xscale, ykey, yscale): opts_dict = { 'margin': { 'l': 40, 'b': 40, 't': 10, 'r': 10 }, 'legend': { 'x': 0, 'y': 1 }, 'hovermode': 'closest' } return go.Layout(xaxis={ 'type': xscale, 'title': xkey }, yaxis={ 'type': yscale, 'title': ykey }, **opts_dict)
Example #8
Source File: viz.py From ConvLab with MIT License | 6 votes |
def create_label(y_col, x_col, title=None, y_title=None, x_title=None, legend_name=None): '''Create label dict for go.Layout with smart resolution''' legend_name = legend_name or y_col y_col_list, x_col_list, legend_name_list = ps.map_( [y_col, x_col, legend_name], util.cast_list) y_title = str(y_title or ','.join(y_col_list)) x_title = str(x_title or ','.join(x_col_list)) title = title or f'{y_title} vs {x_title}' label = { 'y_title': y_title, 'x_title': x_title, 'title': title, 'y_col_list': y_col_list, 'x_col_list': x_col_list, 'legend_name_list': legend_name_list, } return label
Example #9
Source File: energy_end_use_intensity.py From CityEnergyAnalyst with MIT License | 6 votes |
def energy_use_intensity(data_frame, analysis_fields, title, output_path): # CREATE FIRST PAGE WITH TIMESERIES traces = [] area = data_frame["GFA_m2"] x = ["Absolute [MWh/yr]", "Relative [kWh/m2.yr]"] for field in analysis_fields: name = NAMING[field] y = [data_frame[field], data_frame[field] / area * 1000] trace = go.Bar(x=x, y=y, name=name, marker=dict(color=COLOR[field])) traces.append(trace) layout = go.Layout(images=LOGO, title=title, barmode='stack', showlegend=True) fig = go.Figure(data=traces, layout=layout) plot(fig, auto_open=False, filename=output_path) return {'data': traces, 'layout': layout}
Example #10
Source File: energy_end_use_intensity.py From CityEnergyAnalyst with MIT License | 6 votes |
def energy_use_intensity_district(data_frame, analysis_fields, title, output_path): traces = [] data_frame_copy = data_frame.copy() # make a copy to avoid passing new data of the dataframe around the class for field in analysis_fields: data_frame_copy[field] = data_frame_copy[field] * 1000 / data_frame_copy["GFA_m2"] # in kWh/m2y data_frame_copy['total'] = data_frame_copy[analysis_fields].sum(axis=1) data_frame_copy = data_frame_copy.sort_values(by='total', ascending=False) # this will get the maximum value to the left x = data_frame_copy["Name"].tolist() for field in analysis_fields: y = data_frame_copy[field] name = NAMING[field] trace = go.Bar(x=x, y=y, name=name, marker=dict(color=COLOR[field])) traces.append(trace) layout = go.Layout(images=LOGO, title=title, barmode='stack', yaxis=dict(title='Energy Use Intensity [kWh/m2.yr]'), showlegend=True) fig = go.Figure(data=traces, layout=layout) plot(fig, auto_open=False, filename=output_path) return {'data': traces, 'layout': layout}
Example #11
Source File: peak_load_supply.py From CityEnergyAnalyst with MIT License | 6 votes |
def peak_load_building(data_frame, analysis_fields, title, output_path): # CREATE FIRST PAGE WITH TIMESERIES traces = [] area = data_frame["GFA_m2"] data_frame = data_frame[analysis_fields] x = ["Absolute [kW] ", "Relative [W/m2]"] for field in analysis_fields: y = [data_frame[field], data_frame[field] / area * 1000] name = NAMING[field] trace = go.Bar(x=x, y=y, name=name, marker=dict(color=COLOR[field])) traces.append(trace) layout = go.Layout(images=LOGO, title=title, barmode='group', yaxis=dict(title='Peak Load'), showlegend=True) fig = go.Figure(data=traces, layout=layout) plot(fig, auto_open=False, filename=output_path) return {'data': traces, 'layout': layout}
Example #12
Source File: peak_load_supply.py From CityEnergyAnalyst with MIT License | 6 votes |
def peak_load_district(data_frame_totals, analysis_fields, title, output_path): traces = [] data_frame_totals['total'] = data_frame_totals[analysis_fields].sum(axis=1) data_frame_totals = data_frame_totals.sort_values(by='total', ascending=False) # this will get the maximum value to the left for field in analysis_fields: y = data_frame_totals[field] total_perc = (y / data_frame_totals['total'] * 100).round(2).values total_perc_txt = ["(" + str(x) + " %)" for x in total_perc] name = NAMING[field] trace = go.Bar(x=data_frame_totals["Name"], y=y, name=name, marker=dict(color=COLOR[field])) traces.append(trace) layout = go.Layout(title=title, barmode='group', yaxis=dict(title='Peak Load [kW]'), showlegend=True) fig = go.Figure(data=traces, layout=layout) plot(fig, auto_open=False, filename=output_path) return {'data': traces, 'layout': layout}
Example #13
Source File: motion_capture.py From deep-nrsfm with BSD 3-Clause "New" or "Revised" License | 6 votes |
def get_figure3d(points3d, gt=None, range_scale=1): """Yields plotly fig for visualization""" traces = get_trace3d(points3d, BLUE, BLUE, "prediction") if gt is not None: traces += get_trace3d(gt, RED, RED, "groundtruth") layout = go.Layout( scene=dict( aspectratio=dict(x=0.8, y=0.8, z=2), xaxis=dict(range=(-0.4 * range_scale, 0.4 * range_scale),), yaxis=dict(range=(-0.4 * range_scale, 0.4 * range_scale),), zaxis=dict(range=(-1 * range_scale, 1 * range_scale),),), width=700, margin=dict(r=20, l=10, b=10, t=10)) return go.Figure(data=traces, layout=layout)
Example #14
Source File: technique_mapping.py From DeTTECT with GNU General Public License v3.0 | 5 votes |
def plot_graph(filename, type_graph, output_filename): """ Generates a line graph which shows the improvements on detections through the time. :param filename: the filename of the YAML file containing the techniques administration :param type_graph: indicates the type of the graph: detection or visibility :param output_filename: the output filename defined by the user :return: """ # pylint: disable=unused-variable my_techniques, name, platform = load_techniques(filename) graph_values = [] for t in my_techniques.values(): for item in t[type_graph]: date = get_latest_date(item) if date: yyyymm = date.strftime('%Y-%m') graph_values.append({'date': yyyymm, 'count': 1}) import pandas as pd df = pd.DataFrame(graph_values).groupby('date', as_index=False)[['count']].sum() df['cumcount'] = df['count'].cumsum() if not output_filename: output_filename = 'graph_' + type_graph elif output_filename.endswith('.html'): output_filename = output_filename.replace('.html', '') output_filename = get_non_existing_filename('output/' + output_filename, 'html') import plotly import plotly.graph_objs as go plotly.offline.plot( {'data': [go.Scatter(x=df['date'], y=df['cumcount'])], 'layout': go.Layout(title="# of %s items for %s" % (type_graph, name))}, filename=output_filename, auto_open=False ) print("File written: " + output_filename)
Example #15
Source File: Annual_costs.py From CityEnergyAnalyst with MIT License | 5 votes |
def layout(self): return go.Layout(barmode='relative', yaxis=dict(title=self.titley))
Example #16
Source File: Annual_emissions.py From CityEnergyAnalyst with MIT License | 5 votes |
def layout(self): return go.Layout(barmode='relative', yaxis=dict(title=self.titley))
Example #17
Source File: heating_reset_schedule.py From CityEnergyAnalyst with MIT License | 5 votes |
def layout(self): return go.Layout(xaxis=dict(title='Outdoor Temperature [C]'), yaxis=dict(title='HVAC System Temperature [C]'))
Example #18
Source File: e_Investment_costs.py From CityEnergyAnalyst with MIT License | 5 votes |
def layout(self): return go.Layout(barmode='relative', yaxis=dict(title=self.titley), xaxis=dict(categoryorder = 'array', categoryarray = [x for _, x in sorted(zip(self.data_clean['TAC_sys_USD'], self.data_clean['individual_name']))]) )
Example #19
Source File: energy_final_use.py From CityEnergyAnalyst with MIT License | 5 votes |
def layout(self): return go.Layout(barmode='stack', yaxis=dict(title='Energy Demand [MWh/yr]'), xaxis=dict(title='Building Name'), showlegend=True)
Example #20
Source File: peak_load.py From CityEnergyAnalyst with MIT License | 5 votes |
def layout(self): return go.Layout(barmode='group', yaxis=dict(title='Peak Demand [kW]'), showlegend=True, xaxis=dict(title='Building Name'))
Example #21
Source File: peak_load.py From CityEnergyAnalyst with MIT License | 5 votes |
def diversity_factor(data_frame_timeseries, data_frame_totals, analysis_fields, title, output_path): traces = [] x = ["Aggregated [MW] ", "System [MW]"] for field in analysis_fields: y1 = data_frame_totals[field + '0_kW'].sum() / 1000 y2 = data_frame_timeseries[field + '_kWh'].max() / 1000 y = [y1, y2] trace = go.Bar(x=x, y=y, name=field.split('0', 1)[0]) traces.append(trace) layout = go.Layout(title=title, barmode='stack', yaxis=dict(title='Peak Load [MW]')) fig = go.Figure(data=traces, layout=layout) plot(fig, auto_open=False, filename=output_path)
Example #22
Source File: d_energy_loss_bar.py From CityEnergyAnalyst with MIT License | 5 votes |
def layout(self): return go.Layout(barmode='stack', yaxis=dict(title='Energy [kWh/yr]'), xaxis=dict(title='Name'))
Example #23
Source File: data_source_mapping.py From DeTTECT with GNU General Public License v3.0 | 5 votes |
def plot_data_sources_graph(filename, output_filename): """ Generates a line graph which shows the improvements on numbers of data sources through time. :param filename: the filename of the YAML file containing the data sources administration :param output_filename: the output filename defined by the user :return: """ # pylint: disable=unused-variable my_data_sources, name, platform, exceptions = _load_data_sources(filename) graph_values = [] for t in my_data_sources.values(): if t['date_connected']: yyyymm = t['date_connected'].strftime('%Y-%m') graph_values.append({'date': yyyymm, 'count': 1}) import pandas as pd df = pd.DataFrame(graph_values).groupby('date', as_index=False)[['count']].sum() df['cumcount'] = df['count'].cumsum() if not output_filename: output_filename = 'graph_data_sources' elif output_filename.endswith('.html'): output_filename = output_filename.replace('.html', '') output_filename = get_non_existing_filename('output/' + output_filename, 'html') import plotly import plotly.graph_objs as go plotly.offline.plot( {'data': [go.Scatter(x=df['date'], y=df['cumcount'])], 'layout': go.Layout(title="# of data sources for " + name)}, filename=output_filename, auto_open=False ) print("File written: " + output_filename)
Example #24
Source File: Swings.py From ElliotWaveAnalysis with GNU General Public License v3.0 | 5 votes |
def graph_OHLC(self): #not quite there, but the other one works, which is what i really care about OHLC_trace = go.Ohlc(x=self.OHLC_data.Date_Time, open=self.OHLC_data.Open, high=self.OHLC_data.High, low=self.OHLC_data.Low, close=self.OHLC_data.Close, name="OHLC Data", increasing=dict(line=dict(color= '#408e4a')), decreasing=dict(line=dict(color= '#cc2718'))) swing_data = pd.read_csv(self.swing_file, names=['Date_Time', 'Price', 'Direction', 'Row'], parse_dates=True) swing_trace = go.Scatter( x = swing_data.Date_Time, y = swing_data.Price, mode = 'lines+markers', name = 'Swings', line = dict( color = ('rgb(111, 126, 130)'), width = 3) ) data = [OHLC_trace, swing_trace] layout = go.Layout(xaxis = dict(rangeslider = dict(visible = False)), title= self.data_file[:-4]) fig = go.Figure(data=data, layout=layout) py.plot(fig, filename=self.data_file + ".html", output_type='file')
Example #25
Source File: test_vis.py From IRCLogParser with GNU General Public License v3.0 | 5 votes |
def test_csv_heatmap_generator_plotly(self, mock_py): test_data = np.array([[5075, 507, 634, 7237, 3421, 7522, 12180, 9635, 7381, 7967, 6224, 2712, 4758, 2704, 1763, 1869, 4428, 1680], [1652, 425, 269, 982, 2687, 15318, 3865, 3213, 4411, 6821, 1960, 7007, 883, 4592, 0, 3271, 619, 1508], [1578, 924, 409, 1115, 6088, 491, 1923, 10700, 16206, 8690, 1350, 3778, 237, 1095, 20639, 2669, 1956, 6015]]) trace = go.Heatmap( z=test_data, x=list(range(48)), y=list(range(1, 12)), colorscale=[ [0, 'rgb(255, 255, 204)'], [0.13, 'rgb(255, 237, 160)'], [0.25, 'rgb(254, 217, 118)'], [0.38, 'rgb(254, 178, 76)'], [0.5, 'rgb(253, 141, 60)'], [0.63, 'rgb(252, 78, 42)'], [0.75, 'rgb(227, 26, 28)'], [0.88, 'rgb(189, 0, 38)'], [1.0, 'rgb(128, 0, 38)'] ] ) final_data = [trace] layout = go.Layout(title='HeatMap', width=800, height=640) fig = go.Figure(data=final_data, layout=layout) vis.csv_heatmap_generator_plotly(self.test_data_dir + "/vis/", self.test_data_dir, "plotly_heatmap_test") self.assertEqual(mock_py.call_count, 1) self.assertTrue(fig.get('layout') == mock_py.call_args[0][0].get('layout')) np.testing.assert_array_equal(fig.data[0].get('z'), mock_py.call_args[0][0].data[0].get('z'))
Example #26
Source File: vis.py From IRCLogParser with GNU General Public License v3.0 | 5 votes |
def csv_heatmap_generator_plotly(in_directory, output_directory, output_file_name): """ Plots heatmaps for all the csv files in the given directory Args: in_directory (str): location of input csv files output_drectory(str): location to save graph output_file_name(str): name of the image file to be saved Returns: null """ file_list = glob.glob(in_directory+"*.csv") for file in file_list: csv_data = genfromtxt(file, delimiter=',') trace = go.Heatmap( z=csv_data, x=list(range(48)), y=list(range(1, 12)), colorscale=[ [0, 'rgb(255, 255, 204)'], [0.13, 'rgb(255, 237, 160)'], [0.25, 'rgb(254, 217, 118)'], [0.38, 'rgb(254, 178, 76)'], [0.5, 'rgb(253, 141, 60)'], [0.63, 'rgb(252, 78, 42)'], [0.75, 'rgb(227, 26, 28)'], [0.88, 'rgb(189, 0, 38)'], [1.0, 'rgb(128, 0, 38)'] ] ) data = [trace] layout = go.Layout(title='HeatMap', width=800, height=640) fig = go.Figure(data=data, layout=layout) py.image.save_as(fig, filename=in_directory+file[file.rfind("/")+1:-4]+'_heatmap.png')
Example #27
Source File: vis.py From IRCLogParser with GNU General Public License v3.0 | 5 votes |
def generate_group_bar_charts(y_values, x_values, trace_header, output_directory, output_file_name): """ Plots multiple bar graphs on same graph example usage: generate_group_bar_charts([ [5.10114882, 5.0194652482, 4.9908093076], [4.5824497358, 4.7083614037, 4.3812775722], [2.6839471308, 3.0441476209, 3.6403820447] ], ['#kubuntu-devel', '#ubuntu-devel', '#kubuntu'], ['head1', 'head2', 'head3'], '/home/rohan/Desktop/', 'multi_box' ) Args: x_in (list of int): x_axis data y_in (list of int): y_axis data output_drectory(str): location to save graph output_file_name(str): name of the image file to be saved Returns: null """ data = [ go.Bar( x=x_values, y=y_values[i], name=trace_header[i] ) for i in range(len(y_values)) ] layout = go.Layout( barmode='group' ) fig = go.Figure(data=data, layout=layout) py.image.save_as(fig, output_directory + "/" + output_file_name+".png")
Example #28
Source File: draw.py From textprep with MIT License | 5 votes |
def _draw_rate(all_vocabs, all_freqs, output_prefix): biases = np.array( [(s and t) and (s / t if s > t else t / s) or 0 for s, t in all_freqs]) freqs = np.array([s + t for s, t in all_freqs]) hist, bin_edges = np.histogram( biases[biases > 0], weights=freqs[biases > 0], bins=int(max(biases))) bin_centers = bin_edges[:-1] t1 = go.Scatter( x=bin_centers, y=hist, name='num of tokens', mode='lines', fill='tozeroy') share_token_rates = np.cumsum(hist) / sum(freqs) t2 = go.Scatter( x=bin_centers, y=share_token_rates, name='share token rates', mode='lines', yaxis='y2') layout = go.Layout( title='Shared tokens rates', xaxis=dict(title='bias', autorange=True), yaxis=dict(title='num of tokens', type='log', autorange=True), yaxis2=dict( title='accumlative share token rates', autorange=True, side='right', overlaying='y')) fig = go.Figure(data=[t1, t2], layout=layout) py.plot( fig, filename='{}_rate.html'.format(output_prefix), auto_open=False)
Example #29
Source File: sample.py From textprep with MIT License | 5 votes |
def _draw(rs, steps, vocabs, filename): t_r = go.Scatter(x=steps, y=rs, yaxis='y2', name='token sharing rate') t_num_vocabs = go.Bar( y=[len(v) for v in vocabs], x=steps, text=vocabs, name='vocabs') data = [t_r, t_num_vocabs] layout = go.Layout( title='token rate sampling progress', yaxis=dict(title='num of vocabs', type='log'), yaxis2=dict( title='sampled token sharing rate', overlaying='y', side='right')) fig = go.Figure(data=data, layout=layout) py.plot(fig, filename=filename, auto_open=False)
Example #30
Source File: dataproduct_extras.py From tom_base with GNU General Public License v3.0 | 5 votes |
def spectroscopy_for_target(context, target, dataproduct=None): """ Renders a spectroscopic plot for a ``Target``. If a ``DataProduct`` is specified, it will only render a plot with that spectrum. """ spectral_dataproducts = DataProduct.objects.filter(target=target, data_product_type=settings.DATA_PRODUCT_TYPES['spectroscopy'][0]) if dataproduct: spectral_dataproducts = DataProduct.objects.get(data_product=dataproduct) plot_data = [] if settings.TARGET_PERMISSIONS_ONLY: datums = ReducedDatum.objects.filter(data_product__in=spectral_dataproducts) else: datums = get_objects_for_user(context['request'].user, 'tom_dataproducts.view_reduceddatum', klass=ReducedDatum.objects.filter(data_product__in=spectral_dataproducts)) for datum in datums: deserialized = SpectrumSerializer().deserialize(datum.value) plot_data.append(go.Scatter( x=deserialized.wavelength.value, y=deserialized.flux.value, name=datetime.strftime(datum.timestamp, '%Y%m%d-%H:%M:%s') )) layout = go.Layout( height=600, width=700, xaxis=dict( tickformat="d" ), yaxis=dict( tickformat=".1eg" ) ) return { 'target': target, 'plot': offline.plot(go.Figure(data=plot_data, layout=layout), output_type='div', show_link=False) }