Python plotly.graph_objs.Scattergl() Examples

The following are 21 code examples of plotly.graph_objs.Scattergl(). 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: f_paretocurve_convergence.py    From CityEnergyAnalyst with MIT License 7 votes vote down vote up
def calc_graph(self):
        data = self.calc_convergence_metrics()
        traces = []
        for field in self.analysis_fieldsy:
            x = data['generation']
            y = data[field]
            trace = go.Scattergl(x=x, y=y, name=field)
            traces.append(trace)

        total_distance = sum(data['Delta of Generational Distance'])
        y_cumulative = []
        for i in range(len(data['generation'])):
            if i == 0:
                y_acum =  data['Delta of Generational Distance'][i]/total_distance *100
            else:
                y_acum += data['Delta of Generational Distance'][i]/total_distance *100
            y_cumulative.append(y_acum)

        x = data['generation']
        trace = go.Scattergl(x=x, y=y_cumulative, yaxis='y2', name='Cumulative Generational Distance')
        traces.append(trace)

        return traces 
Example #2
Source File: draw.py    From textprep with MIT License 7 votes vote down vote up
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: e_heating_reset_curve.py    From CityEnergyAnalyst with MIT License 6 votes vote down vote up
def supply_return_ambient_temp_plot(data_frame, data_frame_2, analysis_fields, title, output_path):
    traces = []
    for field in analysis_fields:
        y = data_frame[field].values
        # sort by ambient temperature, needs some helper variables
        y_old = np.vstack((np.array(data_frame_2.values.T), y))
        y_new = np.vstack((np.array(data_frame_2.values.T), y))
        y_new[0, :] = y_old[0, :][
            y_old[0, :].argsort()]  # y_old[0, :] is the ambient temperature which we are sorting by
        y_new[1, :] = y_old[1, :][y_old[0, :].argsort()]
        trace = go.Scattergl(x=y_new[0], y=y_new[1], name=NAMING[field],
                           marker=dict(color=COLOR[field]),
                           mode='markers')
        traces.append(trace)

    # CREATE FIRST PAGE WITH TIMESERIES
    layout = dict(images=LOGO, title=title, yaxis=dict(title='Temperature [deg C]'),
                  xaxis=dict(title='Ambient Temperature [deg C]'))

    fig = dict(data=traces, layout=layout)
    plot(fig, auto_open=False, filename=output_path)

    return {'data': traces, 'layout': layout} 
Example #4
Source File: load_curve_supply.py    From CityEnergyAnalyst with MIT License 6 votes vote down vote up
def calc_graph(self):
        data = self.calculate_hourly_loads()
        traces = []
        analysis_fields = self.remove_unused_fields(data, self.analysis_fields)
        for field in analysis_fields:
            y = data[field].values / 1E3  # to MW
            name = NAMING[field]
            trace = go.Bar(x=data.index, y=y, name=name, marker=dict(color=COLOR[field]))
            traces.append(trace)

        data_T = self.calculate_external_temperature()
        for field in ["T_ext_C"]:
            y = data_T[field].values
            name = NAMING[field]
            trace = go.Scattergl(x=data_T.index, y=y, name=name, yaxis='y2', opacity=0.2)
            traces.append(trace)
        return traces 
Example #5
Source File: comfort_chart.py    From CityEnergyAnalyst with MIT License 6 votes vote down vote up
def create_relative_humidity_lines():
    """
    calculates curves of constant relative humidity for plotting (10% - 100% in steps of 10%)

    :return: list of plotly table trace
    :rtype: list of plotly.graph_objs.Scatter
    """

    traces = []

    # draw lines of constant relative humidity for psychrometric chart
    rh_lines = np.linspace(0.1, 1, 10)  # lines from 10% to 100%
    t_axis = np.linspace(-5, 45, 50)
    P_ATM = 101325  # Pa, standard atmospheric pressure at sea level

    for rh_line in rh_lines:

        y_data = calc_constant_rh_curve(t_axis, rh_line, P_ATM)
        trace = go.Scattergl(x=t_axis, y=y_data, mode='lines', name="{:.0%} relative humidity".format(rh_line),
                           line=dict(color=COLORS_TO_RGB['grey_light'], width=1), showlegend=False)
        traces.append(trace)

    return traces 
Example #6
Source File: heating_reset_schedule.py    From CityEnergyAnalyst with MIT License 6 votes vote down vote up
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 #7
Source File: e_heating_reset_curve.py    From CityEnergyAnalyst with MIT License 6 votes vote down vote up
def calc_graph(self):
        traces = []
        data_frame = self.plant_temperatures
        analysis_fields = data_frame.columns
        ambient_temp = self.ambient_temp
        for field in analysis_fields:
            y = data_frame[field].values
            # sort by ambient temperature, needs some helper variables
            y_old = np.vstack((np.array(ambient_temp.values.T), y))
            y_new = np.vstack((np.array(ambient_temp.values.T), y))
            y_new[0, :] = y_old[0, :][
                y_old[0, :].argsort()]  # y_old[0, :] is the ambient temperature which we are sorting by
            y_new[1, :] = y_old[1, :][y_old[0, :].argsort()]
            trace = go.Scattergl(x=y_new[0], y=y_new[1], name=NAMING[field],
                               marker=dict(color=COLOR[field]),
                               mode='markers')
            traces.append(trace)
        return traces 
Example #8
Source File: e_dispatch_curve_heating_plant.py    From CityEnergyAnalyst with MIT License 6 votes vote down vote up
def calc_graph(self):
        # main data about technologies
        data = self.process_individual_dispatch_curve_heating()
        graph = []
        analysis_fields = self.remove_unused_fields(data, self.analysis_fields)
        for field in analysis_fields:
            y = (data[field].values) / 1E6  # into MW
            trace = go.Bar(x=data.index, y=y, name=NAMING[field],
                           marker=dict(color=COLOR[field]))
            graph.append(trace)

        # data about demand
        for field in self.analysis_field_demand:
            y = (data[field].values) / 1E6  # into MW
            trace = go.Scattergl(x=data.index, y=y, name=NAMING[field],
                               line=dict(width=1, color=COLOR[field]))

            graph.append(trace)

        return graph 
Example #9
Source File: f_dispatch_curve_cooling_plant.py    From CityEnergyAnalyst with MIT License 6 votes vote down vote up
def calc_graph(self):
        # main data about technologies
        data = self.process_individual_dispatch_curve_cooling()
        graph = []
        analysis_fields = self.remove_unused_fields(data, self.analysis_fields)
        for field in analysis_fields:
            y = (data[field].values) / 1E6  # into MW
            trace = go.Bar(x=data.index, y=y, name=NAMING[field],
                           marker=dict(color=COLOR[field]))
            graph.append(trace)

        # data about demand
        for field in self.analysis_field_demand:
            y = (data[field].values) / 1E6  # into MW
            trace = go.Scattergl(x=data.index, y=y, name=NAMING[field],
                                 line=dict(width=1, color=COLOR[field]))

            graph.append(trace)

        return graph 
Example #10
Source File: f_pump_duration_curve.py    From CityEnergyAnalyst with MIT License 5 votes vote down vote up
def calc_graph(analysis_fields, data_frame):
    graph = []
    duration = range(HOURS_IN_YEAR)
    x = [(a - min(duration)) / (max(duration) - min(duration)) * 100 for a in duration]  # calculate relative values
    for field in analysis_fields:
        data_frame = data_frame.sort_values(by=field, ascending=False)
        y = data_frame[field].values
        trace = go.Scattergl(x=x, y=y, name=field, fill='tozeroy', opacity=0.8,
                           marker=dict(color=COLOR[field]))
        graph.append(trace)
    return graph 
Example #11
Source File: b_demand_curve.py    From CityEnergyAnalyst with MIT License 5 votes vote down vote up
def calc_graph(self):
        data_frame = self.calc_data_frame()
        traces = []
        x = data_frame.index
        for field in data_frame.columns:
            y = data_frame[field].values
            name = NAMING[field]
            trace = go.Scattergl(x=x, y=y, name=name,
                                 marker=dict(color=COLOR[field]))
            traces.append(trace)
        return traces 
Example #12
Source File: f_pump_duration_curve.py    From CityEnergyAnalyst with MIT License 5 votes vote down vote up
def calc_graph(self):
        analysis_fields = ["P_loss_kWh"]  # data to plot
        data_frame = self.plant_pumping_requirement_kWh
        data_frame.columns = analysis_fields
        graph = []
        duration = range(HOURS_IN_YEAR)
        x = [(a - min(duration)) / (max(duration) - min(duration)) * 100 for a in duration]  # calculate relative values
        for field in analysis_fields:
            data_frame = data_frame.sort_values(by=field, ascending=False)
            y = data_frame[field].values
            trace = go.Scattergl(x=x, y=y, name=field, fill='tozeroy', opacity=0.8,
                               marker=dict(color=COLOR[field]))
            graph.append(trace)
        return graph 
Example #13
Source File: d_dispatch_curve_electricity.py    From CityEnergyAnalyst with MIT License 5 votes vote down vote up
def calc_graph(self):
        # main data about technologies
        data = self.process_individual_dispatch_curve_electricity()
        graph = []
        analysis_fields = self.remove_unused_fields(data, self.analysis_fields)
        for field in analysis_fields:
            y = (data[field].values) / 1E6  # into MWh
            trace = go.Bar(x=data.index, y=y, name=NAMING[field],
                           marker=dict(color=COLOR[field]))
            graph.append(trace)

        # data about demand
        data_req = self.process_individual_requirements_curve_electricity()
        for field in self.analysis_field_demand:
            y = (data_req[field].values) / 1E6 # into MWh
            trace = go.Scattergl(x=data.index, y=y, name=NAMING[field],
                               line=dict(width=1, color=COLOR[field]))

            graph.append(trace)

        # data about exports
        analysis_fields_exports = self.remove_unused_fields(data, self.analysis_fields_exports)
        for field in analysis_fields_exports:
            y = (data[field].values) / 1E6  # into MWh
            trace = go.Bar(x=data.index, y=y, name=NAMING[field],
                           marker=dict(color=COLOR[field]))

            graph.append(trace)

        return graph 
Example #14
Source File: heating_reset_schedule.py    From CityEnergyAnalyst with MIT License 5 votes vote down vote up
def calc_graph(self):
        traces = []
        data = self.data
        x = data["T_ext_C"].values
        data = data.replace(0, np.nan)
        for field in self.analysis_fields:
            y = data[field].values
            name = NAMING[field]
            trace = go.Scattergl(x=x, y=y, name=name, mode='markers', marker=dict(color=COLOR[field]))
            traces.append(trace)
        return traces 
Example #15
Source File: load_duration_curve.py    From CityEnergyAnalyst with MIT License 5 votes vote down vote up
def calc_graph(self):
        graph = []
        duration = range(HOURS_IN_YEAR)
        x = [(a - min(duration)) / (max(duration) - min(duration)) * 100 for a in duration]
        self.analysis_fields = self.remove_unused_fields(self.data, self.analysis_fields)
        for field in self.analysis_fields:
            name = NAMING[field]
            y = self.data.sort_values(by=field, ascending=False)[field].values
            trace = go.Scattergl(x=x, y=y, name=name, fill='tozeroy', opacity=0.8,
                               marker=dict(color=COLOR[field]))
            graph.append(trace)
        return graph 
Example #16
Source File: load_duration_curve.py    From CityEnergyAnalyst with MIT License 5 votes vote down vote up
def calc_graph(analysis_fields, data_frame):
    graph = []
    duration = range(HOURS_IN_YEAR)
    x = [(a - min(duration)) / (max(duration) - min(duration)) * 100 for a in duration]
    for field in analysis_fields:
        name = NAMING[field]
        data_frame_new = data_frame.sort_values(by=field, ascending=False)
        y = data_frame_new[field].values
        trace = go.Scattergl(x=x, y=y, name=name, fill='tozeroy', opacity=0.8,
                           marker=dict(color=COLOR[field]))
        graph.append(trace)

    return graph 
Example #17
Source File: load_duration_curve_supply.py    From CityEnergyAnalyst with MIT License 5 votes vote down vote up
def calc_graph(self):
        graph = []
        duration = range(HOURS_IN_YEAR)
        x = [(a - min(duration)) / (max(duration) - min(duration)) * 100 for a in duration]
        self.analysis_fields = self.remove_unused_fields(self.data, self.analysis_fields)
        for field in self.remove_unused_fields(self.data, self.analysis_fields):
            name = NAMING[field]
            data = self.data.sort_values(by=field, ascending=False)
            y = data[field].values
            trace = go.Scattergl(x=x, y=y, name=name, fill='tozeroy', opacity=0.8, marker=dict(color=COLOR[field]))
            graph.append(trace)
        return graph 
Example #18
Source File: comfort_chart.py    From CityEnergyAnalyst with MIT License 5 votes vote down vote up
def calc_graph(dict_graph):
    """
    creates scatter of comfort and curves of constant relative humidity

    :param dict_graph: contains comfort conditions to plot, output of comfort_chart.calc_data()
    :type dict_graph: dict
    :return: traces of scatter plot of 4 comfort conditions
    :rtype: list of plotly.graph_objs.Scatter
    """

    traces = []

    # draw scatter of comfort conditions in building
    trace = go.Scattergl(x=dict_graph['t_op_occupied_winter'], y=dict_graph['x_int_occupied_winter'],
                       name='occupied hours winter', mode='markers', marker=dict(color=COLORS_TO_RGB['red']))
    traces.append(trace)
    trace = go.Scattergl(x=dict_graph['t_op_unoccupied_winter'], y=dict_graph['x_int_unoccupied_winter'],
                       name='unoccupied hours winter', mode='markers', marker=dict(color=COLORS_TO_RGB['blue']))
    traces.append(trace)
    trace = go.Scattergl(x=dict_graph['t_op_occupied_summer'], y=dict_graph['x_int_occupied_summer'],
                       name='occupied hours summer', mode='markers', marker=dict(color=COLORS_TO_RGB['purple']))
    traces.append(trace)
    trace = go.Scattergl(x=dict_graph['t_op_unoccupied_summer'], y=dict_graph['x_int_unoccupied_summer'],
                       name='unoccupied hours summer', mode='markers', marker=dict(color=COLORS_TO_RGB['orange']))
    traces.append(trace)

    return traces 
Example #19
Source File: a_pareto_curve.py    From CityEnergyAnalyst with MIT License 5 votes vote down vote up
def calc_graph(self):
        graph = []

        # This includes the point of today's emissions
        data_today = self.process_today_system_performance()
        data_today = self.normalize_data(data_today, self.normalization, self.objectives)
        xs = data_today[self.objectives[0]].values
        ys = data_today[self.objectives[1]].values
        name = "Today"
        trace = go.Scattergl(x=xs, y=ys, mode='markers', name="Today's system", text=name,
                             marker=dict(size=18, color='black', line=dict(color='black',width=2)))
        graph.append(trace)

        # PUT THE PARETO CURVE INSIDE
        data = self.process_generation_total_performance_pareto_with_multi()
        data = self.normalize_data(data, self.normalization, self.objectives)
        xs = data[self.objectives[0]].values
        ys = data[self.objectives[1]].values
        zs = data[self.objectives[2]].values

        individual_names = data['individual_name'].values

        trace = go.Scattergl(x=xs, y=ys, mode='markers', name='Pareto optimal systems', text=individual_names,
                             marker=dict(size=18, color=zs,
                                         colorbar=go.ColorBar(title=self.titlez, titleside='bottom'),
                                         colorscale='Jet', showscale=True, opacity=0.8))
        graph.append(trace)

        # This includes the points of the multicriteria assessment in here
        final_dataframe = calc_final_dataframe(data)
        xs = final_dataframe[self.objectives[0]].values
        ys = final_dataframe[self.objectives[1]].values
        name = final_dataframe["Attribute"].values
        trace = go.Scattergl(x=xs, y=ys, mode='markers', name="Multi-criteria system", text=name,
                             marker=dict(size=18, color='white', line=dict(
                                 color='black',
                                 width=2)))
        graph.append(trace)

        return graph 
Example #20
Source File: analysis.py    From cryodrgn with GNU General Public License v3.0 4 votes vote down vote up
def ipy_plot_interactive_annotate(df, ind, opacity=.3):
    import plotly.graph_objs as go
    from ipywidgets import interactive
    if 'labels' in df.columns:
        text = [f'Class {k}: index {i}' for i,k in zip(df.index, df.labels)] # hovertext
    else:
        text = [f'index {i}' for i in df.index] # hovertext
    xaxis, yaxis = df.columns[0], df.columns[1]
    scatter = go.Scattergl(x=df[xaxis], 
                           y=df[yaxis], 
                           mode='markers',
                           text=text,
                           marker=dict(size=2,
                                       opacity=opacity,
                                       ))
    sub = df.loc[ind]
    text = [f'{k}){i}' for i,k in zip(sub.index, sub.labels)]
    scatter2 = go.Scatter(x=sub[xaxis],
                            y=sub[yaxis],
                            mode='markers+text',
                            text=text,
                            textposition="top center",
                            textfont=dict(size=9,color='black'),
                            marker=dict(size=5,color='black'))
    f = go.FigureWidget([scatter,scatter2])
    f.update_layout(xaxis_title=xaxis, yaxis_title=yaxis)
    
    def update_axes(xaxis, yaxis, color_by, colorscale):
        scatter = f.data[0]
        scatter.x = df[xaxis]
        scatter.y = df[yaxis]
        
        scatter.marker.colorscale = colorscale
        if colorscale is None:
            scatter.marker.color = None
        else:
            scatter.marker.color = df[color_by] if color_by != 'index' else df.index
    
        scatter2 = f.data[1]
        scatter2.x = sub[xaxis]
        scatter2.y = sub[yaxis]
        with f.batch_update(): # what is this for??
            f.layout.xaxis.title = xaxis
            f.layout.yaxis.title = yaxis
        
    widget = interactive(update_axes, 
                    yaxis = df.select_dtypes('number').columns, 
                    xaxis = df.select_dtypes('number').columns,
                    color_by = df.columns,
                    colorscale = [None,'hsv','plotly3','deep','portland','picnic','armyrose'])
    return widget, f 
Example #21
Source File: analysis.py    From cryodrgn with GNU General Public License v3.0 4 votes vote down vote up
def ipy_plot_interactive(df, opacity=.3):
    import plotly.graph_objs as go
    from ipywidgets import interactive
    if 'labels' in df.columns:
        text = [f'Class {k}: index {i}' for i,k in zip(df.index, df.labels)] # hovertext
    else:
        text = [f'index {i}' for i in df.index] # hovertext
    
    xaxis, yaxis = df.columns[0], df.columns[1]
    f = go.FigureWidget([go.Scattergl(x=df[xaxis],
                                  y=df[yaxis],
                                  mode='markers',
                                  text=text,
                                  marker=dict(size=2,
                                              opacity=opacity,
                                              color=np.arange(len(df)),
                                              colorscale='hsv'
                                             ))])
    scatter = f.data[0]
    N = len(df)
    f.update_layout(xaxis_title=xaxis, yaxis_title=yaxis)
    f.layout.dragmode = 'lasso'

    def update_axes(xaxis, yaxis, color_by, colorscale):
        scatter = f.data[0]
        scatter.x = df[xaxis]
        scatter.y = df[yaxis]
        
        scatter.marker.colorscale = colorscale
        if colorscale is None:
            scatter.marker.color = None
        else:
            scatter.marker.color = df[color_by] if color_by != 'index' else df.index
        with f.batch_update(): # what is this for??
            f.layout.xaxis.title = xaxis
            f.layout.yaxis.title = yaxis
 
    widget = interactive(update_axes, 
                         yaxis=df.select_dtypes('number').columns, 
                         xaxis=df.select_dtypes('number').columns,
                         color_by = df.columns,
                         colorscale = [None,'hsv','plotly3','deep','portland','picnic','armyrose'])

    t = go.FigureWidget([go.Table(
                        header=dict(values=['index']),
                        cells=dict(values=[df.index]),
                        )])

    def selection_fn(trace, points, selector):
        t.data[0].cells.values = [df.loc[points.point_inds].index]

    scatter.on_selection(selection_fn)
    return widget, f, t