1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90
| def single_color_scatter(ax1, x, y, xlable: str, ylable: str, xlim: list = None, title: str = None, ylim: list = None , color: str = 'k', ): import seaborn as sns import matplotlib.patches as mpl_patches from sklearn.metrics import mean_squared_error sns.set_style('white')
max_lim = np.max([np.max(x), np.max(y)]) min_lim = np.min([np.min(x), np.min(y)]) x_11 = np.linspace(min_lim, max_lim) y_11 = x_11 N = len(x)
result = regress2(x.flatten(), y.flatten()) Slope = result['slope'] Intercep = result['intercept'] y_fit = Slope * x + Intercep rmse = round(np.sqrt(mean_squared_error(x.flatten(), y.flatten())), 5) r = round(result['r'], 5) bias = (np.sum((y - x) / x)) / N
line11, = ax1.plot(x_11, y_11, color='k', linewidth=1.5, linestyle='--', label='1:1 line', zorder=5) linefit, = ax1.plot(x, y_fit, color='r', linewidth=2, linestyle='-', label='fitted line', zorder=5)
ax1.scatter(x, y, edgecolor=None, c=color, s=50, marker='s', facecolors="None", zorder=3) fontdict1 = {"size": 30, "color": 'k', 'family': 'Time New Roman'}
ax1.set_xlabel(xlable, fontdict=fontdict1) ax1.set_ylabel(ylable, fontdict=fontdict1) ax1.grid(False) l0 = ax1.legend(handles=[line11, linefit], loc='lower right', prop={"size": 25}) labels = ax1.get_xticklabels() + ax1.get_yticklabels() [label.set_fontname('Time New Roman') for label in labels] for spine in ['top', 'bottom', 'left', 'right']: ax1.spines[spine].set_color('k') ax1.tick_params(left=True, bottom=True, direction='in', labelsize=30) titlefontdict = {"size": 40, "color": 'k', 'family': 'Time New Roman'} ax1.set_title(title, titlefontdict, pad=20) h1fontdict = {"size": 25, 'weight': 'bold'}
handles = [mpl_patches.Rectangle((0, 0), 1, 1, fc="white", ec="white", lw=0, alpha=0)] * 6 text = [r'$r:$' + str(r), r'$RMSE:$' + str(rmse), r'$Slope:$' + str(round(Slope, 3)), r'$Intercept:$' + str(round(Intercep, 3)), r'$Bias:$' + str(round(100 * bias, 3)) + '%', r'$N:$' + str(N)] l1 = ax1.legend(handles, text, loc='upper left', fancybox=True, framealpha=0, prop=h1fontdict)
h2text_font = {'size': '10', 'weight': 'medium'} label_font = {'size': '10', 'weight': 'medium'}
orderhand = [mpl_patches.Rectangle((0, 0), 1, 1, fc="white", ec="white", lw=0, alpha=0)] ax1.add_artist(l1) ax1.add_artist(l0) if xlim is not None: ax1.set_xlim(xlim) else: ax1.set_xlim(min_lim, max_lim) if ylim is not None: ax1.set_ylim(ylim) else: ax1.set_ylim(min_lim, max_lim)
|