Esempio n. 1
0
    def plotly(self):
        """

        Returns:

        """
        fieldmap = _pd.read_csv(self.FNAME,
                                skiprows=8,
                                names=['Y', 'Z', 'X', 'BY', 'BZ', 'BX'],
                                sep=r'\s+')
        fieldmap['X'] = fieldmap['X'] + self.length.m_as('cm') / 2
        fieldmap['Z_ABS'] = fieldmap['Z'].apply(_np.abs)
        fieldmap = fieldmap[fieldmap['Z'] == fieldmap['Z_ABS'].min()]

        rotation_matrix = _np.linalg.inv(
            self.entry_patched.get_rotation_matrix())
        origin = self.entry_patched.origin

        u = _np.dot(fieldmap[['X', 'Y', 'Z']].values, rotation_matrix)
        fieldmap['XG'] = (u[:, 0] + origin[0].m_as('cm')) / 100
        fieldmap['YG'] = (u[:, 1] + origin[1].m_as('cm')) / 100
        fieldmap['ZG'] = (u[:, 2] + origin[2].m_as('cm')) / 100

        return _go.Histogram2d(
            histfunc='avg',
            nbinsx=100,
            nbinsy=100,
            x=fieldmap['XG'],
            y=fieldmap['YG'],
            z=fieldmap['BZ'],
            opacity=1.0,
            colorscale='Greys',
        )
Esempio n. 2
0
def plot_all2d(users, column):
    fig = make_subplots(rows=2, cols=3, 
                   shared_xaxes='all', 
                   shared_yaxes='all',
                   subplot_titles=list(users.type.unique()))
    for i, value in enumerate(users.groupby('type')):
        key, df = value
        fig.add_trace(go.Histogram2d(x=df[column_x], y=df[column_y]), row=int(i/3)+1, col=(i%3)+1)
    fig.update_layout(height=600, width=800,
                      title_text=column_x+'/'+column_y,showlegend=False)
    return fig
Esempio n. 3
0
    def histogram2d(self, x: List[float], y: List[float], title: str,
                    names: List[str]):
        fig = go.Figure()

        histogram = go.Histogram2d(x=x, y=y, colorbar=dict(title=names[2]))
        fig.add_trace(histogram)

        fig.update_layout(title=title,
                          xaxis_title=names[0],
                          yaxis_title=names[1])

        fig.show(renderer='svg')
Esempio n. 4
0
def plot_2D_Hist(samples,nbins,xlims=None,ylims=None):
	std = np.std(samples,axis=0)
	fig = go.Figure()
	if(xlims==None):
		xbin_dict = dict(size=std[0]*6/nbins)
	else:
		xbin_dict = dict(start=xlims[0],end=xlims[1],size=(xlims[1]-xlims[0])/nbins)
	if(ylims==None):
		ybin_dict = dict(size=std[1]*6/nbins)
	else:
		ybin_dict = dict(start=ylims[0],end=ylims[1],size=(ylims[1]-ylims[0])/nbins)
	fig.add_trace(go.Histogram2d(
		    x=samples[:,0],
		    y=samples[:,1],
		    xbins=xbin_dict,
		    ybins=ybin_dict,
		    colorscale="hot",
		    showscale=True))

	fig = set_basic_layout(fig)
	return fig
Esempio n. 5
0
def plotDataset(datasetFile, batch=True):
    """
    Plot the dataset

    Args:
      datasetFile (str) : Path to dataset file
    """
    logging.info("Got file: %s", datasetFile)

    df = pd.read_csv(datasetFile)

    # Let's plot all features
    logging.info("Plotting features")
    figures = []
    for var in [x for x in df.columns if x not in ["time", "y", "x28", "x61"]]:
        figures.append(go.Scatter(x=df.time, y=df[var], name=var))

    if not batch:
        fig = go.Figure(figures)
        fig.show()

    # PCA
    logging.info("Plotting Scree-plot")
    dfForPCA = df.copy()
    dfForPCA = dfForPCA.drop(["time", "y", "x28", "x61"], axis=1)
    logging.debug("N columns for PCA: %s", len(dfForPCA.columns))
    logging.debug("n Samples for PCA: %s", len(dfForPCA))
    dfForPCA = StandardScaler().fit_transform(dfForPCA)
    pca = PCA()
    pca.fit(dfForPCA)
    logging.debug("nComponents of PCA: %s", pca.n_components_)
    logging.debug("nFeatures of PCA: %s", pca.n_features_)
    logging.debug("nSamples of PCA: %s", pca.n_samples_)

    if not batch:
        fig = px.bar(pca.explained_variance_ratio_)
        fig.update_layout(title="Scree plot",
                          xaxis_title="PCs",
                          yaxis_title="Variance ratio")
        fig.show()

    logging.info("PLotting cumulative variance")
    varSum = np.cumsum(
        np.round(pca.explained_variance_ratio_, decimals=3) * 100)
    if not batch:
        fig = px.line(varSum)
        fig.update_layout(title="Cummulative variance",
                          xaxis_title="PCs",
                          yaxis_title="% Variance explained")
        fig.show()

    # Correlation
    logging.info("Plotting correlation matrix")
    dfForCorr = df.copy()
    dfForCorr = dfForCorr.drop(["time", "y", "x28", "x61"], axis=1)
    corr = dfForCorr.corr()

    if not batch:
        fig = go.Figure(data=[
            go.Heatmap(
                z=corr,
                x=corr.columns,
                y=corr.columns,
                colorscale=[[0, 'rgb(12,51,131)'], [0.25, 'rgb(10,136,186)'],
                            [0.5, 'rgb(242,211,56)'],
                            [0.75, 'rgb(242,143,56)'], [1, 'rgb(217,30,30)']])
        ])
        fig.update_layout(title="Feature Correlation")
        fig.show()

    logging.info("Plotting 2D correlations")
    dfFor2DCorr = df.copy()
    dfFor2DCorr = dfFor2DCorr.drop(["time", "y", "x28", "x61"], axis=1)
    dfFor2DCorr = pd.DataFrame(StandardScaler().fit_transform(dfFor2DCorr),
                               columns=dfFor2DCorr.columns)
    figures = []
    figures_titles = []
    for var1, var2 in itertools.combinations(list(dfFor2DCorr.columns), 2):
        logging.debug("Correlation for %s / %s", var1, var2)
        figures.append(go.Histogram2d(x=dfFor2DCorr[var1],
                                      y=dfFor2DCorr[var2]))
        figures_titles.append((var1, var2))

    SubplotsPerPlot = (3, 3)

    nSubplotsPerPlot = SubplotsPerPlot[0] * SubplotsPerPlot[1]
    nTotal = len(dfFor2DCorr.columns)

    if round(nTotal / nSubplotsPerPlot) < nTotal / nSubplotsPerPlot:
        nPlots = round(nTotal / nSubplotsPerPlot) + 1
    else:
        nPlots = round(nTotal / nSubplotsPerPlot)

    logging.debug("Subplots : %s", SubplotsPerPlot)
    logging.debug("nTotal : %s", nTotal)
    logging.debug("nPlosts : %s", nPlots)

    iPLotted = 0
    for i in range(nPlots):
        fig = make_subplots(SubplotsPerPlot[0], SubplotsPerPlot[1])
        for ir in range(SubplotsPerPlot[0]):
            for ic in range(SubplotsPerPlot[1]):
                logging.debug(
                    "Plot %s -- iPLotted = %s / row = %s / column = %s", i,
                    iPLotted, ir + 1, ic + 1)
                fig.add_trace(figures[iPLotted], row=ir + 1, col=ic + 1)
                fig.update_xaxes(title_text=figures_titles[iPLotted][0],
                                 row=ir + 1,
                                 col=ic + 1)
                fig.update_yaxes(title_text=figures_titles[iPLotted][1],
                                 row=ir + 1,
                                 col=ic + 1)
                iPLotted += 1
        if not batch:
            fig.show()
Esempio n. 6
0
def plot_obtained_pareto_front(art_type=None, problem_name=None):
    art_names = dict(progressive='Progressive',
                     apriori='A priori',
                     aposteriori='A posteriori')

    global save_path
    load_path = '/home/kemal/Programming/Python/Articulation/data/pickles/' + art_type + '/' + problem_name + '/'
    entries = os.listdir(load_path)
    f1 = np.zeros(len(entries))
    f2 = np.zeros(len(entries))
    for i in range(len(entries)):
        file = open(load_path + entries[i], 'rb')
        data = pickle.load(file)
        file.close()
        f1[i] = data['global_best_sol'].get_y()[0]
        f2[i] = data['global_best_sol'].get_y()[1]

    fig = go.Figure()
    fig.add_trace(
        go.Histogram2d(name='Obtained Pareto front',
                       x=f1,
                       y=f2,
                       autobinx=False,
                       autobiny=False,
                       xbins=dict(start=-300, end=0, size=15),
                       ybins=dict(start=0, end=200, size=15),
                       colorscale='YlGnBu',
                       colorbar=dict(title='<b>Number of optimums:</b>',
                                     titleside='top')))
    load_path = '/home/kemal/Programming/Python/Articulation/data/precomputed_data/'
    file = open(load_path + problem_name + '_data.pickle', 'rb')
    data = pickle.load(file)
    file.close()
    f1 = data['pareto_f1']
    f2 = data['pareto_f2']
    fig.add_trace(
        go.Scatter(name='Actual Pareto front',
                   x=f1,
                   y=f2,
                   mode='markers',
                   line=dict(color='red'),
                   marker_size=7))
    fig.update_layout(title={
        'text':
        str('<b>' + art_names[art_type] + ' ' + problem_name +
            ': actual and obtained Pareto front' + '</b>'),
        'y':
        0.93,
        'x':
        0.5,
        'xanchor':
        'center',
        'yanchor':
        'top'
    },
                      xaxis_title='<b>f1</b>',
                      yaxis_title='<b>f2</b>',
                      legend_title='<b>Legend:</b>')

    fig.show()
    fig.write_image(save_path + art_type + '_' + problem_name +
                    '_front_density.png')
Esempio n. 7
0
import plotly.graph_objects as go
import numpy as np

np.random.seed(1)

x = np.random.randn(500)
y = np.random.randn(500)+1

fig = go.Figure(go.Histogram2d(
        x=x,
        y=y
    ))
fig.show()
Esempio n. 8
0
            )
        ),
    row=1, col=2)

bin_size = (max_lwd-min_lwd)/32

fig.add_trace(
    go.Histogram2d(
        x=obs_lwd,
        y=fov_lwd,
        colorscale='BuPu',
        zauto=False,
        zmax=15,
        xbins=dict(
            start=min_lwd,
            end=max_lwd,
            size=bin_size
            ),
        ybins=dict(
            start=min_lwd,
            end=max_lwd,
            size=bin_size
            ),
        ),
    row=1, col=2)

fig.add_trace(
    go.Scatter(
        x=[min_lwd+75, min_lwd+75, min_lwd+75, min_lwd+75, min_lwd+75, min_lwd+75],
        y=[max_lwd-25, max_lwd-45, max_lwd-65, max_lwd-85, max_lwd-105, max_lwd-125],
        mode="text",
def Histogram2D_tseng(filename, data, SNR=0, EVM=0, bercount=(0, 0, 0)):
    x = np.real(data)
    y = np.imag(data)
    miny = y.min()
    fig = go.Figure()
    filename = str(filename)
    # fig.add_trace(go.Histogram2dContour(
    #     x=x,
    #     y=y,
    #     colorscale='Hot',
    #     reversescale=True,
    #     xaxis='x',
    #     yaxis='y'
    # ))
    # fig.add_trace(go.Scatter(
    #     x=x,
    #     y=y,
    #     xaxis='x',
    #     yaxis='y',
    #     mode='markers',
    #     marker=dict(
    #         color='rgba(255,156,0,1)',
    #         size=3)
    # ))
    # fig.add_trace(go.Histogram(
    #     y=y,
    #     xaxis='x2',
    #     marker=dict(
    #         color='#F58518'
    #     )
    # ))
    # fig.add_trace(go.Histogram(
    #     x=x,
    #     yaxis='y2',
    #     marker=dict(
    #         color='#F58518'
    #     )
    # ))
    # if SNR != 0:
    #     fig.add_annotation(
    #         text='SNR:{:.2f}(dB)<br>EVM:{:.2f}(%)<br>Bercount:{:.2E} [{}/{}]'.format(SNR, EVM * 100, bercount[0],
    #                                                                                        bercount[1], bercount[2]),
    #         align='left',
    #         showarrow=False,
    #         font_family='Arial',
    #         font_size=17,
    #         font_color='white',
    #         bgcolor='black',
    #         # xref='x2',
    #         x=0,
    #         y=miny - 0.3,
    #         bordercolor='orange',
    #         borderwidth=5
    #         )
    # fig.add_annotation(
    #     x=0,
    #     y=miny-0.3,
    #     text="SNR = {:.2f}(dB)".format(SNR),
    #     showarrow=False)
    fig.add_trace(
        go.Histogram2d(
            x=x,
            y=y,
            colorscale=[[0.0, "rgb(255, 255, 255)"],
                        [0.1111111111111111, "rgb(255,230,0)"],
                        [0.2222222222222222, "rgb(255,150,0)"],
                        [0.3333333333333333, "rgb(255,102,0)"],
                        [0.4444444444444444, "rgb(254,051,0)"],
                        [0.5555555555555556, "rgb(255,0,0)"],
                        [0.6666666666666666, "rgb(255,0,51)"],
                        [0.7777777777777778, "rgb(153,0,51)"],
                        [0.8888888888888888, "rgb(60,0,30)"],
                        [1.0, "rgb(35,0, 0)"]],
            nbinsx=256,
            nbinsy=256,
            zauto=True,
        ))
    fig.update_layout(
        autosize=False,
        xaxis=dict(zeroline=False,
                   domain=[0, 1],
                   fixedrange=True,
                   mirror=True,
                   ticks='inside',
                   showline=True,
                   linewidth=2,
                   linecolor='black',
                   showticklabels=False),
        yaxis=dict(zeroline=False,
                   domain=[0, 1],
                   fixedrange=True,
                   mirror=True,
                   ticks='inside',
                   showline=True,
                   linewidth=2,
                   linecolor='black',
                   showticklabels=False),
        xaxis2=dict(zeroline=False,
                    domain=[0.905, 1],
                    fixedrange=True,
                    mirror=True,
                    ticks='inside',
                    showline=True,
                    linewidth=2,
                    linecolor='black',
                    showticklabels=False),
        yaxis2=dict(zeroline=False,
                    domain=[0.905, 1],
                    fixedrange=True,
                    mirror=True,
                    ticks='inside',
                    showline=True,
                    linewidth=2,
                    linecolor='black',
                    showticklabels=False),
        height=800,
        width=800,
        bargap=0,
        hovermode='closest',
        showlegend=False,
        title=go.layout.Title(text="Color Histogram---" + filename),
        font=dict(family="Arial", size=20, color="Black"),
        # yaxis_range=[-4.3, 4.3],
        # xaxis_range=[-4.3, 4.3]
    )
    if SNR != 0:
        fig.update_layout(
            xaxis=dict(
                zeroline=False,
                domain=[0, 0.9],
                showgrid=True,
                fixedrange=True,
                title=
                'In-Phase<br>SNR:{:.2f}(dB) || EVM:{:.2f}(%) || Bercount:{:.2E} [{}/{}]'
                .format(SNR, EVM * 100, bercount[0], bercount[1], bercount[2]),
            ),
            font=dict(family="Arial", size=20, color="Black"),
        )
    fig.write_image(
        "G:\KENG\pycharm\pycharm_coherent_16QAM\data\KENG_optsim_py\{}.pdf".
        format(filename))
Esempio n. 10
0
# +

list(nx.cluster._directed_triangles_and_degree_iter(G.subgraph(['albamoraleda','antonialaborde','EduLorenGarcia'])))
# -

all_profiles_with_network['clustering_network'] = all_profiles_with_network.apply(lambda x: sum([t[3]/2 for t in nx.cluster._directed_triangles_and_degree_iter(x.ego_network) ])/3, axis=1) #if t[0]!=x.screen_name

compare_groups_plot(all_profiles_with_network, 'clustering_network','Outlier connectness')

from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(rows=4, cols=1, shared_xaxes=True)
for i, g in enumerate(all_profiles[selected].groupby('type_profile')):
    g_id, g = g
    fig.add_trace(go.Histogram2d(x=g.edges_reciprocal_ego, y=g.ego_network.apply(len), name=g_id),col=1, row=i+1, )
fig.update_layout(title='Degree of ego-network', height=700)

from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(rows=4, cols=1, shared_xaxes=True)
for i, g in enumerate(all_profiles[has_network].groupby('type_profile')):
    g_id, g = g
    fig.add_trace(go.Histogram(x=g['edges_between_outliers']/g.ego_network.apply(lambda x: (len(x)-1)*(len(x)-2)), name=g_id),col=1, row=i+1, )
fig.update_layout(title='Edges between outliers', height=700)

from plotly.subplots import make_subplots
import plotly.graph_objects as go
fig = make_subplots(rows=4, cols=1, shared_xaxes=True)
for i, g in enumerate(all_profiles[has_network].groupby('type_profile')):
    g_id, g = g
Esempio n. 11
0
def Histogram2D(filename, data, Image_Address, SNR=0, EVM=0, BERcount=0):
    x = np.real(data)
    y = np.imag(data)
    miny = y.min()
    fig = go.Figure()
    filename = str(filename)
    # fig.add_trace(go.Histogram2dContour(
    #     x=x,
    #     y=y,
    #     colorscale='Hot',
    #     reversescale=True,
    #     xaxis='x',
    #     yaxis='y'
    # ))
    # fig.add_trace(go.Scatter(
    #     x=x,
    #     y=y,
    #     xaxis='x',
    #     yaxis='y',
    #     mode='markers',
    #     marker=dict(
    #         color='rgba(255,156,0,1)',
    #         size=3)
    # ))
    fig.add_trace(go.Histogram(y=y, xaxis='x2', marker=dict(color='#F58518')))
    fig.update_yaxes(range=[-9, 9])
    fig.update_layout(yaxis=dict(
        tickmode='array',
        tickvals=[-7, -5, -3, -1, 1, 3, 5, 7],
    ))

    fig.add_trace(go.Histogram(x=x, yaxis='y2', marker=dict(color='#F58518')))
    fig.update_xaxes(range=[-9, 9])
    fig.update_layout(xaxis=dict(
        tickmode='array',
        tickvals=[-7, -5, -3, -1, 1, 3, 5, 7],
    ))

    # if SNR != 0:
    #     fig.add_annotation(
    #         x=0,
    #         y=miny-0.2,
    #         text="SNR = {}(dB)".format(SNR),
    #         showarrow=False)
    #     fig.add_annotation(
    #         x=0,
    #         y=miny-0.35,
    #         text="EVM = {}(%)".format(EVM * 100),
    #         showarrow=False)
    fig.add_trace(
        go.Histogram2d(x=x,
                       y=y,
                       colorscale='Hot',
                       nbinsx=256,
                       nbinsy=256,
                       zauto=True))
    fig.update_layout(autosize=False,
                      xaxis=dict(zeroline=False,
                                 domain=[0, 0.85],
                                 showgrid=False,
                                 fixedrange=True),
                      yaxis=dict(zeroline=False,
                                 domain=[0, 0.85],
                                 showgrid=False,
                                 fixedrange=True),
                      xaxis2=dict(zeroline=False,
                                  domain=[0.86, 1],
                                  showgrid=False,
                                  fixedrange=True),
                      yaxis2=dict(zeroline=False,
                                  domain=[0.86, 1],
                                  showgrid=False,
                                  fixedrange=True),
                      height=800,
                      width=800,
                      bargap=0,
                      hovermode='closest',
                      showlegend=False,
                      title=go.layout.Title(text="Color Histogram---" +
                                            filename),
                      xaxis_title="In-Phase",
                      yaxis_title="Quadrature-Phase",
                      font=dict(family="Time New Roman",
                                size=16,
                                color="Black"))
    if SNR != 0:
        fig.update_layout(xaxis_title="SNR : {}_EVM : {}_BERcount : {}".format(
            SNR, EVM, BERcount))
    # fig.write_image(r"data\KENG_optsim_py\20201130_DATA_2Laser_final\noLW_1GFO_noNoise_80KM_initialphase225\image\{}.png".format(filename))
    fig.write_image(Image_Address + "\{}.png".format(filename))
Esempio n. 12
0
# fig = go.Figure(go.Histogram2d(x=X_sorted_org_scale[:, 0].flatten(),
# y=Y_pred_ordered_org_scale[:, 0].flatten()-Y_pred_reduced_org_scale[:, 0].flatten()))
# seasons_No = 6
# fig = go.Figure()
# for i in range(seasons_No):
#     start_hour = int((i/seasons_No)*8760)
#     end_hour = int(((i+1)/seasons_No)*8760)
#     fig.add_trace(go.Scatter(x=X[start_hour:end_hour, 0].flatten(),
#     y=Y_pred_org_scale[start_hour:end_hour, 0].flatten()-
#     scaler_Y.inverse_transform(Y_pred_reduced)[start_hour:end_hour,0], mode='markers', name=str(i)))
# fig.update_layout(title="Residual Demand vs. DPrice in seasons")
# # fig.update_yaxes(range=[-2, 0])
# # fig.update_xaxes(range=[20000, 80000])
# fig.show()

fig = go.Figure(go.Histogram2d(x=res_gen[orders],
                               y=Y_pred_ordered_org_scale[:, 0].flatten() - Y_pred_reduced_org_scale[:, 0].flatten()))
# fig = go.Figure(go.Scatter(x=wind_data_year_tech[orders],
# y=Y_pred_ordered_org_scale[:, 0].flatten()-Y_pred_reduced_org_scale[:, 0].flatten(), mode='markers', name='Original'))
fig.update_layout(title="RES vs. DPrice")
fig.show()

xx = X_sorted_org_scale.sum(axis=1)
fig = go.Figure(
    go.Histogram2d(x=xx, y=Y_pred_ordered_org_scale[:, 0].flatten() - Y_pred_reduced_org_scale[:, 0].flatten()))
# fig = go.Figure(go.Scatter(x=xx, y=Y_pred_ordered_org_scale[:, 0].flatten()-Y_pred_reduced_org_scale[:, 0].flatten(),
# mode='markers', name='Original'))
fig.update_layout(title="Sum neighbours vs. DPrice")
fig.show()

print(clf.cv_results_)
print(clf.best_estimator_)