Пример #1
0
def _update_experiment_comparison_plot(experiment_table_data,
                                       experiment_table_selected_rows,
                                       hidden_columns, anchor, data):
    """The callback to render a new experiment comparison plot.

    Triggered when new rows in the experiment table are selected.
    or deselected.
    """
    if experiment_table_selected_rows is None or len(
            experiment_table_selected_rows) == 0:
        return [html.Div()]

    commit_hash = data["commit_hash"]
    selected_experiment_ids = [
        experiment_table_data[row]["id"]
        for row in experiment_table_selected_rows
    ]

    anchor_data, dimensions = app._rubicon_model.get_dimensions(
        commit_hash, selected_experiment_ids, hidden_columns, anchor)

    return [
        dcc.Graph(figure=go.Figure(
            go.Parcoords(
                line=dict(
                    color=anchor_data, colorscale="plasma", showscale=True),
                dimensions=dimensions,
            )))
    ]
Пример #2
0
def updateParCord(begin_year, end_year, selected_region):

    selected_year = []

    if not isinstance(selected_region, list):
        selected_region = [selected_region]
    for i in range(int(begin_year), int(end_year) + 1):
        selected_year.append(int(i))

    filtered_df = df.loc[df['iyear'].isin(selected_year)]
    df_by_continent = filtered_df[df['country_txt'].isin(selected_region)]
    # print(selected_region)
    country_val = []
    for i in range(len(selected_region)):
        for j in range(len(country)):
            if selected_region[i] == country[j]:
                country_val.append(country_no[j])
    # print(country_val)
    figure = go.Figure(data=go.Parcoords(
        line=dict(
            color=df_by_continent['country'],
            colorscale='thermal',
        ),
        dimensions=list([
            {
                'label': 'Weapon Type',
                'range': [0, len(weaptype_no) + 1],
                'tickvals': weaptype_no,
                'ticktext': weaptype,
                'values': df_by_continent['weaptype1'].tolist()
            },
            {
                'label': 'Country',
                'range': [min(country_val),
                          max(country_val) + 1],
                'tickvals': country_val,
                'ticktext': selected_region,
                'values': df_by_continent['country'].tolist()
            },
            {
                'label': 'Attack Type',
                'range': [0, len(attack_type_no)],
                'tickvals': attack_type_no,
                'ticktext': attack_type,
                'values': df_by_continent['attacktype1'].tolist()
            },
            {
                'label': 'Success',
                'range': [0, 1],
                'tickvals': [0, 1],
                'ticktext': ['No Success', 'Success'],
                'values': df_by_continent['success'].tolist()
            },
        ])))

    figure.update_layout(title='Parallel Plot for terrorism data',
                         plot_bgcolor='#FFFFE0',
                         paper_bgcolor='#FFFFE0',
                         height=450)
    return figure
Пример #3
0
def plot_parallel_coordinates(expsdf, colslabels, categcols, tickslabels,
                              outdir):

    dimensions = []
    for col in categcols:  # categorical columns
        colname = colslabels[col]
        plotcol = dict(label=colname,
                       values=expsdf[col],
                       tickvals=list(range(len(tickslabels[col]))),
                       ticktext=tickslabels[col])
        dimensions.append(plotcol)

    dimensions.append(dict(
        label='Convergence time',
        values=expsdf['t'],
    ))

    dimensions.append(dict(
        label='Infected ratio',
        values=expsdf['inf'],
    ))

    fig = go.Figure(
        data=go.Parcoords(line_color='blue', dimensions=dimensions))
    plotpath = pjoin(outdir, 'parallel.html')
    plotly.offline.plot(fig, filename=plotpath, auto_open=False)
Пример #4
0
def traffic_parallel_coords(df, max_value=50000, range=[0.8, 1]):
    df = df[df.target < max_value]
    dimensions = []

    for col in [
            'traff_m5', 'traff_m4', 'traff_m3', 'traff_m2', 'traff_m1',
            'target'
    ]:
        dimensions.append(
            dict(range=[0, max_value],
                 tickvals=[0, 20, max_value * 0.5, 120, max_value],
                 label=col,
                 values=df[col]))
        if col == 'target':
            dimensions[-1]['constraintrange'] = [
                max_value * range[0], max_value * range[1]
            ]

    fig = go.Figure(
        data=go.Parcoords(line=dict(color=df['target'],
                                    colorscale=px.colors.sequential.Rainbow,
                                    showscale=True,
                                    cmin=0,
                                    cmax=max_value),
                          dimensions=list(dimensions)))
    # fig.update_layout(template='plotly_dark', paper_bgcolor='rgba(0,0,0,0)',
    #                   plot_bgcolor='rgba(0,0,0,0)', font=dict(color="white", size=18, ), width=1100, height=600)
    return fig
def draw_plotly_go_parallel_coordinates_matrix(dataDF):

    # Converting the professor attribute into int datatype
    dataDF['professor'] = pd.to_numeric(dataDF['professor'])

    # Calculate the min, max and range to be used while defining the range
    dimensions = [
        "lecture", "participants", "professional expertise", "motivation",
        "clear presentation", "overall impression"
    ]

    min_max_range = {}
    for col in dimensions:
        min_max_range[col] = [
            dataDF[col].min(), dataDF[col].max(),
            np.ptp(dataDF[col])
        ]

    # Reference : https://plotly.com/python/parallel-coordinates-plot/
    # Usage : Advanced Parallel Coordinates Plot

    figure = go.Figure(data=go.Parcoords(
        line=dict(color=dataDF['professor'],
                  colorsrc="professor",
                  colorscale='Rainbow',
                  showscale=False),
        dimensions=list([
            dict(range=[(dataDF['professor'].min() -
                         1), (dataDF['professor'].max() + 1)],
                 label="Professor Number",
                 values=dataDF['professor']),
            dict(range=[(dataDF['lecture'].min() -
                         1), (dataDF['lecture'].max() + 1)],
                 label="Lecture Number",
                 values=dataDF['lecture']),
            dict(range=[(dataDF['participants'].min() -
                         1), (dataDF['participants'].max() + 1)],
                 label="Participants",
                 values=dataDF['participants']),
            dict(range=[6, 0],
                 tickvals=[1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6],
                 label='Professional Expertise',
                 values=dataDF['professional expertise']),
            dict(range=[6, 0],
                 tickvals=[1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6],
                 label='Motivation',
                 values=dataDF['motivation']),
            dict(range=[6, 0],
                 tickvals=[1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6],
                 label='Clean Presentation',
                 values=dataDF['clear presentation']),
            dict(range=[6, 0],
                 tickvals=[1, 1.5, 2, 2.5, 3, 3.5, 4, 4.5, 5, 5.5, 6],
                 label='Overall impression',
                 values=dataDF['overall impression'])
        ])))

    figure.update_layout(title="Parallel Co-ordinates of Weierstrass-Prize")
    figure.show()
Пример #6
0
def create_graphs(dff, title):
    return [{
        'data': [{
            'x': dff['YearRemodel'],
            'name': 'Year Remodel',
            'type': 'histogram'
        }, {
            'x': dff['YearBuilt'],
            'name': 'Year Built',
            'type': "histogram"
        }],
        'layout': {
            'plot_bgcolor': colors['background'],
            'paper_bgcolor': colors['background'],
            'title': title + " Neighborhood(s)",
            'font': {
                'color': colors['text']
            }
        },
    }, {
        'data': [
            go.Parcoords(line=dict(color=dff['SalePrice'],
                                   colorscale='Electric',
                                   showscale=True,
                                   cmin=df['SalePrice'].min(),
                                   cmax=df['SalePrice'].max()),
                         dimensions=list([
                             dict(label='SalePrice',
                                  values=dff['SalePrice'].unique()),
                             dict(label='"OverallCond"',
                                  values=df["OverallCond"].unique()),
                             dict(label="GrLivArea",
                                  values=df["GrLivArea"].unique()),
                             dict(label="TotRmsAbvGrd",
                                  values=df["TotRmsAbvGrd"].unique()),
                             dict(label="YrSold", values=df["YrSold"].unique())
                         ]))
        ],
        'layout':
        dict(title=title + " Neighborhood",
             plot_bgcolor=colors['background'],
             paper_bgcolor=colors['background'])
    }, {
        'data': [
            go.Heatmap(x=dff.columns.values[8:],
                       y=dff['Neighborhood'].unique(),
                       z=dff[[
                           "GrLivArea", "GarageArea", "TotRmsAbvGrd",
                           "TotalBsmtSF", "FullBath"
                       ]].values,
                       colorscale='Electric',
                       colorbar={"title": "Square feet"},
                       showscale=True)
        ],
        "layout":
        go.Layout(title=title + " Neighborhood",
                  plot_bgcolor=colors['background'],
                  paper_bgcolor=colors['background'])
    }]
Пример #7
0
def parallel_coordinates(save_dir, metric="loss"):
    # DO NOT CHANGE ANYTHING IN THIS FUNCTION
    # This function take a folder path and loads all model files,
    # extracts hyperparamaters and the given score, and creates a
    # parallell coordination plot to display the scores for each hyperparamater

    model_files = glob(save_dir + "/*.pt")
    print("models found:", model_files)

    rows = []
    for model_file in model_files:
        model_dict = torch.load(model_file)
        score_dict = model_dict["scores"]
        score_dict["loss"] = model_dict["loss"]
        score_dict["loss"] = score_dict["loss"].cpu().detach().numpy()
        score_dict["loss"] = score_dict["loss"].item()

        row = {"model_name": model_dict["model_name"]}
        row.update(model_dict["hyperparamaters"])
        row[metric] = score_dict[metric]

        rows.append(row)

    df = pd.DataFrame(rows)

    y_dims = []
    for cname, cdata in df.iteritems():
        values = list(cdata.values)

        add_text_ticks = False
        if isinstance(values[0], str):
            ticktexts = sorted(set(values))
            ticktext2id = {v: i for i, v in enumerate(ticktexts)}
            tickvals = list(ticktext2id.values())
            values = [ticktext2id[v] for v in values]
            add_text_ticks = True

        max_v = np.max(values)
        min_v = np.min(values)

        y_dict = {"values": values, "label": cname, "range": [min_v, max_v]}

        if add_text_ticks:
            y_dict["ticktext"] = ticktexts
            y_dict["tickvals"] = tickvals

        y_dims.append(y_dict)

    fig = go.Figure(data=go.Parcoords(
        line=dict(color=df[metric],
                  colorscale='Electric',
                  showscale=True,
                  cmin=df[metric].min(),
                  cmax=df[metric].max()),
        dimensions=y_dims,
    ))

    fig.update_layout(margin=dict(l=120, r=30, b=20, t=40))
    fig.show()
Пример #8
0
def create_parcoords_fig(data=None, columns=None):
    parcoords = go.Figure(
        data=go.Parcoords(line_color='red',
                          dimensions=list([
                              dict(range=[data[col].min(), data[col].max()],
                                   label=col,
                                   values=data[col]) for col in columns
                              if isinstance(data[col].iloc[0], numbers.Number)
                          ])))
    return parcoords
    def _value_path_plot_candidates(
            self,
            zs: np.ndarray,
            names: Optional[List[str]] = None,
            labels: Optional[List[str]] = None) -> Figure:
        """Plots multiple solution candidates as an parallel axis plot.

        Args:
            zs (np.ndarray): A 2D array with each candidate on its' rows.
            names (List[str], optional): A list of the objective names.
        """
        if zs.ndim == 1:
            zs = zs.reshape(1, -1)
        zs_original = self.scaler.inverse_transform(zs)
        zs_original = np.where(self.is_max, -zs_original, zs_original)

        nadir_original = self.scaler.inverse_transform(
            self.nadir.reshape(1, -1))[0]
        nadir_original = np.where(self.is_max, -nadir_original, nadir_original)

        ideal_original = self.scaler.inverse_transform(
            self.ideal.reshape(1, -1))[0]
        ideal_original = np.where(self.is_max, -ideal_original, ideal_original)

        if names is None:
            names = ["Obj {}".format(i + 1) for i in range(zs.shape[1])]

        names = [
            "{} ({})".format(name, val)
            for (val,
                 name) in zip(["⇧" if m is True else "⇩"
                               for m in self.is_max], names)
        ]

        rows = [list(row) for row in zs_original.T]
        fig = go.Figure(data=go.Parcoords(dimensions=list(
            # stupid hack to "label" each solution on the first axis
            [
                dict(
                    range=[1, len(zs_original)],
                    label="Candidate",
                    values=list(range(1,
                                      len(zs_original) + 1)),
                    tickvals=list(range(1,
                                        len(zs_original) + 1)),
                )
            ] + [
                dict(range=[low, up], label=name, values=vals)
                for (low, up, name,
                     vals) in zip(nadir_original, ideal_original, names, rows)
            ])))

        return fig
def plot_optimization(fname='report_sim2_5DoF'):
    """
    make parallel coordinates plot for the hyperparameter optimization results
    """

    df = pd.read_csv(f'./tests/optimization_logs/{fname}.csv')
    df['value'] = -df['value']
    df['params_lr'] = np.log10(df['params_lr'])
    df['params_buffer_size'] = np.log10(df['params_buffer_size'])

    df['params_net_arch'] = df['params_net_arch'].replace(
        ['small', 'medium', 'big'], [16, 32, 64])

    data = [
        go.Parcoords(
            line=dict(color=df['value'],
                      showscale=True,
                      colorscale='thermal',
                      colorbar={'title': 'Return'},
                      cmin=-1000,
                      cmax=-500),
            dimensions=list([
                dict(range=[np.log10(1e-4), np.log10(1e-2)],
                     tickvals=[-4., -3., -2],
                     ticktext=['1E-4', '1E-3', '1E-2'],
                     label='Learning Rate',
                     values=df['params_lr']),
                dict(tickvals=[256, 512],
                     range=[200, 550],
                     label='Minibatch Size',
                     values=df['params_batch_size']),
                dict(tickvals=[1, 50, 100],
                     range=[0, 100],
                     label='Train Frequency',
                     values=df['params_train_freq']),
                dict(tickvals=[np.log10(5e4),
                               np.log10(1e6),
                               np.log10(2e6)],
                     ticktext=['5E4', '1E6', '2E6'],
                     range=[np.log10(2.8e4), np.log10(5e6)],
                     label='Buffer Size',
                     values=df['params_buffer_size']),
                dict(label='Network Width',
                     values=df['params_net_arch'],
                     tickvals=[16, 32, 64])  # , range = [1,3],)
            ]))
    ]

    fig = go.FigureWidget(data=data)
    fig.update_layout(template="plotly")
    fig.write_image("./figures/fig_par_coords2.pdf")
    return
Пример #11
0
    def parameter_graph(self):
        if self.performance_metric_selector and len(
                self.hyperparameter_selector) > 0:
            df = self.results[(
                self.results['pipeline_name'].isin(self.pipeline_run_selector))
                              & (self.results['slice_name'] == '')]

            # merge
            extra_df = pd.merge(self.hparam_info,
                                df,
                                on='pipeline_name',
                                how='left')

            dimensions = ['pipeline_name'] + self.hyperparameter_selector + \
                         [self.performance_metric_selector]

            new_dims = []
            for d in dimensions:
                try:
                    new_dims.append({
                        'label': d,
                        'values': pd.to_numeric(extra_df[d])
                    })
                except:
                    u = sorted(
                        list(extra_df[d].apply(lambda x: str(x)).unique()))
                    mapping = {v: i for i, v in enumerate(u)}
                    new_dims.append({
                        'label':
                        d,
                        'tickvals': [mapping[x] for x in u],
                        'ticktext':
                        u,
                        'values':
                        extra_df[d].apply(lambda x: str(x)).map(mapping)
                    })

            final_col = pd.to_numeric(
                extra_df[self.performance_metric_selector])
            fig = go.Figure(data=go.Parcoords(line=dict(color=final_col,
                                                        colorscale='inferno',
                                                        showscale=True,
                                                        cmin=min(final_col),
                                                        cmax=max(final_col)),
                                              dimensions=new_dims))
        else:
            fig = px.scatter(pd.DataFrame(),
                             marginal_y='rug',
                             width=1100,
                             title='Hyperparameter Comparison')

        return fig
Пример #12
0
def adjacency_parallel_coordinate_plot(rules: List):
    '''
        Visualizes the antecedents and consequents of each rule by drawing lines
        representing each rule across identical vertical axis representing the
        potential items in the set
        
        Has the advantage of making it easier to visualize compound rules over
        scatterplots
    '''

    #These two structures track the rules and entities therein based on the number of antecedents/consequents involved
    #Allows us to visualize each number separately in a parallel coordinate graph
    #Note these are indexed 0->2 axis on (no association rule can have less then 2)
    unique_entities_by_axis_count = []
    rules_by_axis_count = []
    for rule in rules:
        axis_required = len(rule.lhs) + 1

        #Filter out rules with multiple consequents
        #TODO consider allowing multiple consequents
        if len(rule.rhs) == 1:
            #If the rules_by_axis_count list lacks a slot for the current number of antacedents, add them
            while len(rules_by_axis_count) < axis_required - 1:
                rules_by_axis_count.append([])
                unique_entities_by_axis_count.append(set())

            #Add the rule and the entities found in its atecedents and consequents to their respective structure
            rules_by_axis_count[axis_required - 2].append(rule)
            unique_entities_by_axis_count[axis_required -
                                          2] = unique_entities_by_axis_count[
                                              axis_required - 2].union(
                                                  set(rule.lhs), set(rule.rhs))

    axis_counter = 2
    for rules, unique_entities in zip(rules_by_axis_count,
                                      unique_entities_by_axis_count):
        unique_entities = list(unique_entities)
        unique_entities = _parallel_coord_axis_optimizer(
            rules, unique_entities, axis_counter)

        line_color = list(map(lambda rule: round(rule.confidence, 2), rules))

        dimensions = _paracoord_builder(rules, unique_entities, axis_counter)
        fig = go.Figure(data=go.Parcoords(line=dict(
            color=line_color, colorscale=[[0, 'white'], [1, 'red']]),
                                          dimensions=dimensions))

        fig.update_layout(plot_bgcolor='white', paper_bgcolor='white')

        fig.show()
        axis_counter += 1
Пример #13
0
def update_figure(value):
    dimensions = []
    for axe in value:
        dimensions.append(
            dict(range=[df[axe].min(), df[axe].max()],
                 tickvals=[],
                 label=axe,
                 values=df[axe]), )
    fig = go.Figure(data=go.Parcoords(line=dict(
        color=df['Year'],
        colorscale='earth',
    ),
                                      dimensions=dimensions))
    return fig
def __create_parallel_coordinates(df_differences, k):
    fig_parallel = go.Figure(data=go.Parcoords(
        line=dict(color=df_differences['Cluster'],
                  colorscale=[CLUSTER_COLORS[i] for i in range(k)]
                  ),
        dimensions=list([
            dict(range=[df_differences[col].min(), df_differences[col].max()],
                 label=col, values=df_differences[col]) for col in MAIN_COLS])
    )
    )
    fig_parallel.update_layout(
        plot_bgcolor='white',
        paper_bgcolor='white'
    )
    return fig_parallel
Пример #15
0
def Technologies_Parallel_Cordianate(Range):
    df = technologies_data[technologies_data["Range Type"] == Range]
    b = df["Range Type"]
    new_list1 = []
    for i in b:
        if i not in new_list1:
            new_list1.append(i)

    a = df["Value"]
    new_list = []
    for i in a:
        if i not in new_list:
            new_list.append(i)

    fig = go.Figure(data=go.Parcoords(dimensions=list([
        dict(tickvals=df["Value"],
             ticktext=df.index,
             label="Technology",
             values=df["Value"]),
        dict(range=[min(df['Delay (ms)']),
                    max(df['Delay (ms)'])],
             label='Delay (ms)',
             values=df['Delay (ms)']),
        dict(range=[min(df['Max Range (m)']),
                    max(df['Max Range (m)'])],
             label='Max Range (m)',
             values=df['Max Range (m)']),
        dict(range=[min(df['Data Rate (Mb/s)']),
                    max(df['Data Rate (Mb/s)'])],
             label='Data Rate (Mb/s)',
             values=df['Data Rate (Mb/s)']),
        dict(range=[
            min(df['Frequency Band(s) (GHz)']),
            max(df['Frequency Band(s) (GHz)'])
        ],
             label='Frequency Band(s) (GHz)',
             values=df['Frequency Band(s) (GHz)']),
        dict(range=[
            min(df['Frequency Band(s) (GHz)']),
            max(df['Frequency Band(s) (GHz)'])
        ],
             label='Frequency Band(s) (GHz)',
             values=df['Frequency Band(s) (GHz)']),
    ])))

    return fig.show()
Пример #16
0
    def parallel_coordinates(df1,cont_feat):
        columns=list(df1.columns)
        labelencoder = LabelEncoder()

        df = df1.copy()

        for i in columns:
            if i not in cont_feat:
                df[i]=labelencoder.fit_transform(df[i])

        new_list=[]
        for i in columns:
            if i in cont_feat:
                x=dict(range = [min(df[i].values.tolist()),max(df[i].values.tolist())],
                         label = i, values = df[i].values.tolist())
                new_list.append(x)
            else:
                x=dict(range = [min(df[i].values.tolist()),max(df[i].values.tolist())],
                         tickvals = list(df[i].unique()),
                         label = i, values = df[i].values.tolist(),
                        ticktext = list(df1[i].unique()))
                new_list.append(x)

        fig = go.Figure(
            data=go.Parcoords(
                line=dict(
                    color = df[explore.outcome_name],
                    colorscale = [[0, 'red'], [0.5, 'red'], [0.5, 'blue'], [1, 'blue']],
                    showscale = True,
                    colorbar=dict(
                        lenmode='pixels',
                        len=75,
                        tickmode='array',
                        tickvals=[0.25, 0.75],
                        ticktext=['0', '1']
                    )
                ),
                dimensions = list(new_list)
            )
        )
        

        fig.show()
Пример #17
0
                def change_plot(change):
                    if only_stable.v_model:
                        mask = dimensions[0]['values'] == 1
                    else:
                        mask = slice(dimensions[0]['values'].size)

                    new_data = []
                    for i in items.v_model:
                        d = dimensions[i]
                        new_data.append(
                            dict(values=d['values'][mask], label=d['label']))

                    fig.children = [
                        go.FigureWidget(
                            go.Parcoords(
                                line=dict(color=dimensions[color.v_model]
                                          ['values'][mask]),
                                dimensions=new_data,
                            ))
                    ]
Пример #18
0
    def parallel_plot(year):
        fig = go.Figure(data=go.Parcoords(
            line=dict(color=new_combined_hap['Year']),
            dimensions=list([
                dict(range=[0, 8],
                     constraintrange=[4, 8],
                     label='Happiness Score',
                     values=new_combined_hap['Happiness Score']),
                dict(range=[0, 8],
                     label='Economy (GDP per Capita)',
                     values=new_combined_hap['Economy (GDP per Capita)']),
                dict(range=[0, 8],
                     label='Family',
                     values=new_combined_hap['Family']),
                dict(range=[0, 8],
                     label='Health (Life Expectancy)',
                     values=new_combined_hap['Health (Life Expectancy)'])
            ])))

        fig.update_layout(plot_bgcolor='white', paper_bgcolor='white')
        print('parallel done')
        return fig
Пример #19
0
def parallel_coordinates_plot(data, variables, group_var=None):
    """
    Create a parallel coordinates plot based on a given dataframe and a list of variable names
    Args:
        data: dataframe containing the data
        variables: list of variable names
        group_var: variable name to set the color scales for the created lines

    Returns:

    """

    # Remove na values
    plot_data_vars = variables.copy() + [group_var]

    print(plot_data_vars)
    plot_data = data[plot_data_vars].copy()
    plot_data = plot_data.dropna(how="any")

    # create dimensions for parallel
    dimensions = []

    for var in variables:
        label = "<br>".join(textwrap.wrap(var, 30))
        print(label)
        dim = dict(range=[plot_data[var].min(), plot_data[var].max()],
                   label=label,
                   values=plot_data[var])
        dimensions.append(dim)

    fig = go.Figure(
        data=go.Parcoords(line=dict(color=plot_data[group_var],
                                    colorscale=px.colors.diverging.Geyser,
                                    showscale=True),
                          dimensions=dimensions))

    fig.show()
    fig.update_layout(width=1200)
    fig.write_image("parallel_coordinates.png")
def main():
    year = 2014
    elo_rating = elo(year)
    massey_rating = massey(year)
    premier_rating = premier(year)
    teams = elo_rating.keys()
    ranking_df = pd.DataFrame({
        "Team": [],
        "Premier League Rating": [],
        "Massey Rating": [],
        "Elo Rating": []
    })
    for team in teams:
        df_current = pd.Series(
            {
                "Team": team,
                "Premier League Rating": premier_rating[team],
                "Massey Rating": massey_rating[team],
                "Elo Rating": elo_rating[team]
            },
            index=None)
        ranking_df = ranking_df.append(df_current, ignore_index=True)
    # Parallel Plot
    fig = go.Figure(
        data=go.Parcoords(line=dict(color="#002366"),
                          dimensions=list([
                              dict(range=[22, 95],
                                   constraintrange=[4, 8],
                                   label='Premier League',
                                   values=ranking_df['Premier League Rating']),
                              dict(range=[-1.1, 1.6],
                                   label='Masseys Method',
                                   values=ranking_df['Massey Rating']),
                              dict(range=[1117, 1300],
                                   label='Elo',
                                   values=ranking_df['Elo Rating'])
                          ])))
    fig.update_layout(plot_bgcolor='red', paper_bgcolor='white')
    fig.show()
Пример #21
0
def return_parallel_plot_fig( GEOID_to_plot = "ALL_SEASONS", height = 800):
    # 3) Plot:
    fig = go.Figure(
        data = go.Parcoords(
            # LINE COLOR DEF: 
            line = dict( 
               color = parallelDF[colorCol],                                        # each lines' color val
               colorscale = ["purple", "lightcoral", "red", "firebrick","maroon"],  # [counties0->4]
               colorbar = dict(
                   tickvals = [0,1,2,3,4],                                          # [counties0->4]
                   ticktext = countyColorOrder,                                     # [counties0->4]
                   title = {'text': "NYC Counties"},
                   x = -0.5,                                                        # ******delete this to turn the colorscale bar to normal position
                   ticks = "outside",
               ),
               showscale = True,                                                    # show the scale 
               cmin = parallelDF[colorCol].min(),
               cmax = parallelDF[colorCol].max(),
            ),
            dimensions = making_dimension_list_for_parallel(GEOID_to_plot),
            labelangle = -45,
        )
    )

    fig.update_layout(
        title = "Focused look on Season Gas Leak Reports and Total Crime of all GEOID in NYC",
        autosize=False,
        width  = widthPlot,#1000,
        height = height,#700,
        margin=dict(
            l=10,
            r=100,
            b=10,
            t=200,
            pad=4
        ),
    )
    return fig
Пример #22
0
    def change_plot(self, change):
        if self.only_stable.v_model:
            mask = self.results[0]['values'] == 1
        else:
            mask = slice(self.results[0]['values'].size)

        new_data = []
        for i in self.items.v_model:
            d = self.results[i]
            new_data.append(dict(values=d['values'][mask], label=d['label']))

        self.fig.children = [
            go.FigureWidget(
                go.Parcoords(
                    line=dict(color=self.results[self.color.v_model]['values']
                              [mask]),
                    dimensions=new_data,
                ))
        ]

        self.plotly_plot.children = [
            self.color, self.items, self.only_stable, self.fig
        ]
Пример #23
0
    def repr(self) -> go.Figure:
        fig = go.Figure()
        # rearange colors
        colors = []
        for idx, ens in enumerate(self._colors):
            colors.append([idx / len(self._colors), self._colors[ens]])
            colors.append([(idx + 1) / len(self._colors), self._colors[ens]])
        # create a single dataframe, where all ensemble parameters are stacked
        data_df = pd.concat(list(self.data.values()))
        # drop a column with ids
        ensemble_ids = data_df["ensemble_id"]
        data_df = data_df.drop("ensemble_id", axis=1)
        # create parallel coordinates dimension list
        dimensions = []
        for parameter in data_df:
            dimensions.append(dict(label=parameter, values=data_df[parameter]))
        fig.add_trace(
            go.Parcoords(
                line=dict(
                    color=ensemble_ids,
                    colorscale=colors,
                    showscale=True,
                    colorbar=dict(
                        tickvals=list(range(0, len(self.data))),
                        ticktext=list(self.data.keys()),
                        len=0.2 * len(self.data),
                        title="Ensemble",
                    ),
                ),
                dimensions=dimensions,
                labelangle=45,
                labelside="top",
            ))
        fig.update_layout(clickmode="event+select")
        fig.update_layout(uirevision=True)

        return fig
Пример #24
0
def pc_imputed(df, imp_arr, df_excl, save_fig=True, dataset=None):
    # Requires column named imputed

    subset = list(df.columns)
    for item in list(df_excl.columns):
        subset.remove(item)

    df = df[subset]
    df = vis_encode_cols(df.copy())
    imp_arr_num = np.zeros(len(imp_arr))
    imp_arr_num[imp_arr] = 1
    df['imputed'] = imp_arr_num
    dim = []
    for col in df.columns[:-1]:
        col_dict = {}
        col_dict['range'] = [min(df[col]), max(df[col])]
        col_dict['label'] = col
        col_dict['values'] = df[col]
        dim.append(col_dict)

    fig = go.Figure(
        data=go.Parcoords(line=dict(color=df['imputed'],
                                    colorscale="Bluered",
                                    colorbar={
                                        'tickvals': [0, 1],
                                        'ticktext': ["not imputed", "imputed"]
                                    }),
                          dimensions=dim))
    fig.update_layout(title="PC plot visualizing the imputed datapoints")

    if save_fig:
        html_path = "vis/" + dataset[:-4] + "_parallel_coordinates.html"

        fig.write_html(html_path)

    fig.show()
Пример #25
0
def update_parallel_figure(selected_color):
    week_text = [i for i in week_dict]
    week_vals = [week_dict[i] for i in week_text]

    pd_text = [i for i in pd_dict]
    pd_vals = [pd_dict[i] for i in pd_text]

    res_text = [i for i in res_dict]
    res_vals = [res_dict[i] for i in res_text]

    color_text = [i for i in color_dict]
    color_vals = [color_dict[i] for i in color_text]

    fig = go.Figure(data=go.Parcoords(
        line=dict(color=df['Color'],
                  colorscale=selected_color,
                  showscale=True,
                  cmin=min(color_code),
                  cmax=max(color_code),
                  colorbar=dict(tickvals=color_vals, ticktext=color_text)),
        dimensions=list([
            dict(tickvals=week_vals,
                 ticktext=week_text,
                 label='Day of Week',
                 values=df['Week']),
            dict(tickvals=pd_vals,
                 ticktext=pd_text,
                 label='Police Department District',
                 values=df['Pd']),
            dict(tickvals=res_vals,
                 ticktext=res_text,
                 label='Resolution',
                 values=df['Res'])
        ])))

    return fig
Пример #26
0
            def run_parametric_study():
                from pathos.multiprocessing import ProcessingPool
                pool = pp.ProcessPool()
                output = pool.map(run_simulation, args)

                dimensions = [
                    dict(values=np.asarray([o[0] for o in output],
                                           dtype=np.float64),
                         label='stability')
                ]

                dimensions.extend([
                    dict(values=sampling[:, ik], label=f'{k}')
                    for ik, k in enumerate(design_space.keys())
                ])

                for i, r in enumerate(self.responses.widget.v_model):
                    if output[0][i + 1] is not None:
                        dimensions.append(
                            dict(values=np.asarray([o[i + 1] for o in output],
                                                   dtype=np.float64),
                                 label=r))

                for isamp in range(len(sampling)):
                    tmp_design = {
                        f'{k}': sampling[isamp, ik]
                        for ik, k in enumerate(design_space.keys())
                    }
                    tmp_responses = {
                        r: output[isamp][ir + 1]
                        for ir, r in enumerate(self.responses.widget.v_model)
                    }
                    tmp_responses['stability'] = output[isamp][0]
                    simu_path = os.path.join(path, f'simu_{isamp}')
                    save_param_study_for_simu(simu_path, 'param_study.json',
                                              tmp_design, tmp_responses)

                fig = v.Row(children=[
                    go.FigureWidget(data=go.Parcoords(
                        line=dict(color=dimensions[0]['values']),
                        dimensions=dimensions,
                    )),
                ],
                            align='center',
                            justify='center')

                def change_plot(change):
                    if only_stable.v_model:
                        mask = dimensions[0]['values'] == 1
                    else:
                        mask = slice(dimensions[0]['values'].size)

                    new_data = []
                    for i in items.v_model:
                        d = dimensions[i]
                        new_data.append(
                            dict(values=d['values'][mask], label=d['label']))

                    fig.children = [
                        go.FigureWidget(
                            go.Parcoords(
                                line=dict(color=dimensions[color.v_model]
                                          ['values'][mask]),
                                dimensions=new_data,
                            ))
                    ]

                color = v.Select(label='color',
                                 items=[{
                                     'text': v['label'],
                                     'value': i
                                 } for i, v in enumerate(dimensions)],
                                 v_model=0)
                items = v.Select(label='Show items',
                                 items=[{
                                     'text': v['label'],
                                     'value': i
                                 } for i, v in enumerate(dimensions)],
                                 v_model=[i for i in range(len(dimensions))],
                                 multiple=True)
                only_stable = v.Switch(label='Show only stable results',
                                       v_model=False)

                color.observe(change_plot, 'v_model')
                items.observe(change_plot, 'v_model')
                only_stable.observe(change_plot, 'v_model')

                self.plotly_plot.children = [color, items, only_stable, fig]
                self.stop_simulation(None)
)
fig_parallel2 = go.Figure(data=go.Parcoords(
    line=dict(color=df2['colorVal'],
              colorscale='Electric',
              showscale=True,
              cmin=-4000,
              cmax=-100),
    dimensions=list([
        dict(range=[32000, 227900],
             constraintrange=[100000, 150000],
             label="Block Height",
             values=df2['blockHeight']),
        dict(range=[0, 700000], label='Block Width', values=df2['blockWidth']),
        dict(tickvals=[0, 0.5, 1, 2, 3],
             ticktext=['A', 'AB', 'B', 'Y', 'Z'],
             label='Cyclinder Material',
             values=df2['cycMaterial']),
        dict(range=[-1, 4],
             tickvals=[0, 1, 2, 3],
             label='Block Material',
             values=df2['blockMaterial']),
        dict(range=[134, 3154],
             visible=True,
             label='Total Weight',
             values=df2['totalWeight']),
        dict(range=[9, 19984],
             label='Assembly Penalty Wt',
             values=df2['assemblyPW']),
        dict(
            range=[49000, 568000], label='Height st Width', values=df2['HstW'])
    ])))
def get_parallel_coordinate_plot(study=None,coloring="blues",params= None,objective_value="Loss",logLoss=True):

    layout = go.Layout(title="Parallel Coordinate Plot",)

    trials = [trial for trial in study.trials if trial.state == TrialState.COMPLETE]

    if len(trials) == 0:
        _logger.warning("Your study does not have any completed trials.")
        return go.Figure(data=[], layout=layout)

    all_params = {p_name for t in trials for p_name in t.params.keys()}
    if params is not None:
        for input_p_name in params:
            if input_p_name not in all_params:
                raise ValueError("Parameter {} does not exist in your study.".format(input_p_name))
        all_params = set(params)
    sorted_params = sorted(list(all_params))
    
    if logLoss==True:
        for t in trials:
            t.value=-1*np.log(t.value)
    dims = [
        {
            "label": objective_value,
            "values": tuple([t.value for t in trials]),
            "range": (round(min([t.value for t in trials]),3), round(max([t.value for t in trials]),3)),
        }
    ]  # type: List[Dict[str, Any]]
    for p_name in sorted_params:
        values = []
        for t in trials:
            if p_name in t.params:
                values.append(t.params[p_name])
        is_categorical = False
        try:
            tuple(map(float, values))
        except (TypeError, ValueError):
            vocab = defaultdict(lambda: len(vocab))  # type: DefaultDict[str, int]
            values = [vocab[v] for v in values]
            is_categorical = True
        
        dim = {
            "label": name_shortner(p_name),
            "values": tuple(values),
            "range": ( round(min(values),2), round(max(values),2)),
        }
        
        if is_categorical:
            dim["tickvals"] = list(range(len(vocab)))
            ticktext=list(sorted(vocab.items(), key=lambda x: x[1]))
            dim["ticktext"] = [x[0] for x in ticktext]
        if p_name in (["Time Steps", "Latent Size", "Frequency Bins"]):
            dim["tickvals"]= list(set(values))
        dims.append(dim)
    
    traces = [
        go.Parcoords(
            dimensions=dims,
            
            tickfont=plotly.graph_objs.parcoords.Tickfont(color="black",size=18,family="Times New Roman"),
            rangefont=plotly.graph_objs.parcoords.Rangefont(color="white",size=1,family="Times New Roman"),
            line={
                "color": dims[0]["values"],
                
                "colorscale": coloring,
                "colorbar": {"title": objective_value},
                "showscale": True,
#                 "reversescale":True,
            },
        )
    ]

    figure = go.Figure(data=traces, layout=layout)
    
    return figure
# plotting Parallel Coordinates for the data frame
fig2 = go.Figure(data=go.Parcoords(
    line=dict(color=num,
              colorscale='HSV',
              showscale=False,
              cmin=0,
              cmax=len(countries_in_europe)),
    dimensions=list([
        dict(range=[0, len(countries_in_europe)],
             tickvals=c,
             ticktext=countries_in_europe,
             label="countries",
             values=num),
        dict(range=[
            0, max(recent_deaths_data_frame['hospital_beds_per_thousand'])
        ],
             label="Hospitals beds per 1000",
             values=recent_deaths_data_frame['hospital_beds_per_thousand']),
        dict(range=[0, max(recent_deaths_data_frame['median_age'])],
             label='Median Age',
             values=recent_deaths_data_frame['median_age']),
        dict(range=[0, max(recent_deaths_data_frame['population'])],
             label='Population',
             values=recent_deaths_data_frame['population']),
        dict(range=[0, max(recent_deaths_data_frame['life_expectancy'])],
             label='Life expectancy',
             values=covid19_data_frame['life_expectancy']),
        dict(range=[0, max(recent_deaths_data_frame['covid19_death_rate'])],
             label='COVID-19 Death rate',
             values=recent_deaths_data_frame['covid19_death_rate']),
    ])),
                 layout=go.Layout(autosize=True,
    ))
for col in df:
    if col == "Geoid" or col == "CountyName" or col == "CensusTract_2010_NAME":
        continue
    parallelBarForCol = dict(range=[df[col].min(), df[col].max()],
                             label=col,
                             values=df[col])
    dimList.append(parallelBarForCol)

# 3) Plot:
colorCol = "TotalCrime"
figParallel = go.Figure(data=go.Parcoords(
    # LINE COLOR DEF:
    line=dict(
        color=df[colorCol],  #each lines' color val
        colorscale="Electric",
        showscale=True,  #show the scale 
        cmin=df[colorCol].min(),
        cmax=df[colorCol].max()),
    dimensions=dimList))

figParallel.update_layout(
    autosize=False,
    width=5000,
    height=1000,
)
figParallel.update_yaxes(
    tickangle=45,
    #  tickfont=dict(family='Rockwell', color='crimson', size=14)
)