utils.py
def plot_scatter(x, y, add_unit_line=True, add_R2=True, layout_kwargs=None):
    '''
    makes a scatter plot with Plotly
    :param x: numpy array
    :param y: numpy array
    :param add_unit_line: boolean. whether to add a line x=y
    :param add_R2: boolean. whether to add text of R2 on the plot
    :param layout_kwargs: a dictionary, according to plotly API:
        https://plotly.com/python/figure-labels/#manual-labelling-with-graph-objects
        https://plotly.com/python-api-reference/generated/plotly.graph_objects.Figure.html?highlight=update%20layout#plotly.graph_objects.Figure.update_layout
        https://plotly.com/python-api-reference/generated/plotly.graph_objects.Layout.html
        for example:
        1. layout_kwargs = dict(title='scatter', xaxis_title='X', legend_title='legend', showlegend=True)
        2. layout_kwargs = dict(title=dict(text='scatter'), xaxis=dict(title={'text': 'X'}))
    :return: plotly figure object
    '''

    unit_line = [np.nanmin(np.append(x, y)), np.nanmax(np.append(x, y))]
    # calculate explained variance:
    R2 = round(explained_variance_score(x, y), 3)
    fig = go.Figure()

    # Add traces
    fig.add_trace(go.Scatter(x=x, y=y,
                             mode='markers',
                             name='')
                  )

    if add_R2:
        fig.add_annotation(
            x=unit_line[0],
            y=unit_line[1],
            showarrow=False,
            text=f'R2 score is: {R2}')

    if add_unit_line:
        fig.add_trace(go.Scatter(x=unit_line, y=unit_line,
                                 mode='lines',
                                 name=''))
    fig.update_layout(showlegend=False)

    if layout_kwargs:
        fig.update_layout(**layout_kwargs)
    return fig

    makes a scatter plot with Plotly
    :param x: numpy array
    :param y: numpy array
    :param add_unit_line: boolean. whether to add a line x=y
    :param add_R2: boolean. whether to add text of R2 on the plot
    :param layout_kwargs: a dictionary, according to plotly API:
        https://plotly.com/python/figure-labels/#manual-labelling-with-graph-objects
        https://plotly.com/python-api-reference/generated/plotly.graph_objects.Figure.html?highlight=update%20layout#plotly.graph_objects.Figure.update_layout
        https://plotly.com/python-api-reference/generated/plotly.graph_objects.Layout.html
        for example:
        1. layout_kwargs = dict(title='scatter', xaxis_title='X', legend_title='legend', showlegend=True)
        2. layout_kwargs = dict(title=dict(text='scatter'), xaxis=dict(title={'text': 'X'}))
    :return: plotly figure object
    
makes a scatter plot with Plotly
makes a scatter plot with Plotly
def plot_scatter(x, y, add_unit_line=True, add_R2=True, layout_kwargs=None):
    unit_line = [np.nanmin(np.append(x, y)), np.nanmax(np.append(x, y))]
    R2 = round(explained_variance_score(x, y), 3)
    fig = go.Figure()
    fig.add_trace(go.Scatter(x=x, y=y,
                             mode='markers',
                             name='')
                  )
    if add_R2:
        fig.add_annotation(
            x=unit_line[0],
            y=unit_line[1],
            showarrow=False,
            text=f'R2 score is: {R2}')
    if add_unit_line:
        fig.add_trace(go.Scatter(x=unit_line, y=unit_line,
                                 mode='lines',
                                 name=''))
    fig.update_layout(showlegend=False)
    if layout_kwargs:
        fig.update_layout(**layout_kwargs)
    return fig
def plot_scatter ( x , y , add_unit_line = True , add_R2 = True , layout_kwargs = None ) : unit_line = [ np . nanmin ( np . append ( x , y ) ) , np . nanmax ( np . append ( x , y ) ) ] R2 = round ( explained_variance_score ( x , y ) , 3 ) fig = go . Figure ( ) fig . add_trace ( go . Scatter ( x = x , y = y , mode = 'markers' , name = '' ) ) if add_R2 : fig . add_annotation ( x = unit_line [ 0 ] , y = unit_line [ 1 ] , showarrow = False , text = f'R2 score is: {R2}' ) if add_unit_line : fig . add_trace ( go . Scatter ( x = unit_line , y = unit_line , mode = 'lines' , name = '' ) ) fig . update_layout ( showlegend = False ) if layout_kwargs : fig . update_layout ( ** layout_kwargs ) return fig
makes a scatter plot with Plotly
makes a scatter plot with Plotly
'''
    makes a scatter plot with Plotly
    :param x: numpy array
    :param y: numpy array
    :param add_unit_line: boolean. whether to add a line x=y
    :param add_R2: boolean. whether to add text of R2 on the plot
    :param layout_kwargs: a dictionary, according to plotly API:
        https://plotly.com/python/figure-labels/#manual-labelling-with-graph-objects
        https://plotly.com/python-api-reference/generated/plotly.graph_objects.Figure.html?highlight=update%20layout#plotly.graph_objects.Figure.update_layout
        https://plotly.com/python-api-reference/generated/plotly.graph_objects.Layout.html
        for example:
        1. layout_kwargs = dict(title='scatter', xaxis_title='X', legend_title='legend', showlegend=True)
        2. layout_kwargs = dict(title=dict(text='scatter'), xaxis=dict(title={'text': 'X'}))
    :return: plotly figure object
    ''' # calculate explained variance: # Add traces
plotly figure object
plotly figure object
x
None
y
None
add_unit_line
boolean. whether to add a line x=y
boolean . whether to add a line x = y
add_R2
boolean. whether to add text of R2 on the plot
boolean . whether to add text of R2 on the plot
layout_kwargs
None