| 28 | |
| 29 | |
| 30 | def scatterplot_apo(x, y, save_to=None, xlabel=None, ylabel=None, regplot=False): |
| 31 | if len(x) == 0 or len(x) != len(y): |
| 32 | raise ValueError("Invalid input data for scatter plot.") |
| 33 | |
| 34 | fig = plt.figure(figsize=(10, 8)) |
| 35 | if regplot: |
| 36 | sns.regplot(x=x, y=y, color='steelblue', scatter_kws={'s': 10, 'alpha': 0.8, 'edgecolor': 'k'}) |
| 37 | else: |
| 38 | # Create scatter plot |
| 39 | sns.scatterplot(x=x, y=y, color='steelblue', alpha=0.8, edgecolor='k') |
| 40 | |
| 41 | # Add reference line |
| 42 | grid_x = np.linspace(0, 1, 100) |
| 43 | plt.plot(grid_x, grid_x / 2 + 0.5, color='red', linestyle='--') |
| 44 | |
| 45 | # Set plot title and axis labels |
| 46 | xlabel = xlabel if xlabel else "TM_native" |
| 47 | ylabel = ylabel if ylabel else "TM_ensemble" |
| 48 | plt.xlabel(xlabel, fontsize=FONTSIZE) |
| 49 | plt.ylabel(ylabel, fontsize=FONTSIZE) |
| 50 | |
| 51 | # Set plot limits and ticks |
| 52 | plt.xlim(0, 1) |
| 53 | plt.ylim(0, 1) |
| 54 | plt.xticks(fontsize=FONTSIZE) |
| 55 | plt.yticks(fontsize=FONTSIZE) |
| 56 | |
| 57 | if save_to is not None: |
| 58 | plt.savefig(save_to, dpi=FIG_DPI) |
| 59 | plt.close('all') |
| 60 | return save_to |
| 61 | return fig |
| 62 | |
| 63 | # Create the plot |
| 64 | if regplot: |
| 65 | sns.regplot(x=x, y=y, color='steelblue', scatter_kws={'s': 10, 'alpha': 0.8, 'edgecolor': 'k'}) |
| 66 | sns.regplot( |
| 67 | x=x, |
| 68 | y=y, |
| 69 | color='steelblue', |
| 70 | scatter_kws={'s': point_size, 'alpha': alpha, 'edgecolor': 'k'} |
| 71 | ) |
| 72 | else: |
| 73 | # Create scatter plot |
| 74 | sns.scatterplot(x=x, y=y, color='steelblue', alpha=0.8, edgecolor='k') |
| 75 | |
| 76 | sns.scatterplot( |
| 77 | x=x, |
| 78 | y=y, |
| 79 | color='steelblue', |
| 80 | alpha=alpha, |
| 81 | edgecolor='k', |
| 82 | s=point_size |
| 83 | ) |
| 84 | # Add reference line |
| 85 | grid_x = np.linspace(0, 1, 100) |
| 86 | plt.plot(grid_x, grid_x / 2 + 0.5, color='red', linestyle='--') |
| 87 | ax.plot(grid_x, grid_x / 2 + 0.5, color='red', linestyle='--', label='Reference') |