i am new to python and i have been working on trying to plot a scoreplot using matplotlib, however, i kept getting this error, UnboundLocalError: local variable 'x\_min' referenced before assignment.Any tips or suggestions would be appreciated.

this is my code

```
# Plots score plot with data labels
# Pass original data, un-centred scores and returns of PCA to this function. Optional width, height and margin.
# This function returns the axes of the score plot

def scoreplot_label(dt, scores, pca, width=5, height=5, margin=0.5):
    plt.figure(figsize=(width, height))
    # ax = sns.scatterplot(x="PC1", y="PC2", data=scores)
    # I used regplot only because my version of Seaborn is old and does not have scatterplot
    scores['label'] = Y
    ax = sns.lmplot(x='PC1', y='PC2', data=scores, fit_reg=False,
                    scatter_kws={'s':50}, hue='label',
                    scatter=True).set(xlim=(x_min, x_max),
                                      ylim=(y_min, y_max)
                                      ).set_titles("Score plot",
                                                   fontsize=14
                    )

    # (added this section) text for labels
    text_pos = 0.5
    # Print text
    for i, v in enumerate(np.array(scores)):
        ax.text(v[0], v[1]+text_pos, dt.iloc[i,0], color='black',
                ha='center', va='center', fontsize=12)

    # Set limits for figure
    x_min = min(scores['PC1'].min(),0) - margin
    x_max = max(scores['PC1'].max(),0) + margin
    y_min = min(scores['PC2'].min(),0) - margin
    y_max = max(scores['PC2'].max(),0) + margin

    ax.set_xlim(x_min, x_max)
    ax.set_ylim(y_min, y_max)
    ax.set_title("Score plot", fontsize=14)
    plt.plot([x_min, x_max], [0, 0], color='k', linestyle='--', linewidth=1)
    plt.plot([0, 0], [y_min, y_max], color='k', linestyle='--', linewidth=1)
    return ax

    plt.clf
ax3 = scoreplot_label(data, scores2, pca2, width=20, height=20, margin=20)
plt.show()

```

it says the line has some errors followed by the UnboundLocalError: local variable 'x\_min' referenced before assignment

```
---> 10     ax = sns.lmplot(x='PC1',y='PC2',data=scores,fit_reg=False,scatter_kws={'s':50},hue='label',scatter=True).set(xlim=(x_min, x_max),ylim=(y_min, y_max)).set_titles("Score plot", fontsize=14)

```