# 製圖3.0 當你不幸被4r非常不合理的要求每條東西都要有自己顏色的時候😢,可以參考下面 ``` fig, ax = plt.subplots(1,1, figsize=(12, 6)) colors = ['#666666', '#1f77b4', '#1f77b4', '#ff7f0e', '#ff7f0e', '#2ca02c', '#2ca02c', '#d62728', '#d62728', '#9467bd', '#9467bd'] color_box = ['#666666', '#666666', '#1f77b4', '#1f77b4', '#1f77b4', '#ff7f0e', '#ff7f0e', '#2ca02c', '#2ca02c', '#d62728', '#d62728', '#9467bd', '#9467bd'] color_dot = ['#666666', '#666666', '#1f77b4', '#1f77b4', '#ff7f0e', '#ff7f0e', '#2ca02c', '#2ca02c', '#d62728', '#d62728', '#9467bd', '#9467bd'] alphas = [0.9, 0.9, 0.6, 0.9, 0.6, 0.9, 0.6, 0.9, 0.6, 0.9, 0.6, 0.9] alpha_box = [0.6, 0.9, 0.6, 0.9, 0.6, 0.9, 0.6, 0.9, 0.6, 0.9, 0.6, 0.9, 0.6] alpha_dot = [0.7, 0.3, 0.7, 0.3, 0.7, 0.3, 0.7, 0.3, 0.7, 0.3, 0.7, 0.3] sns.boxplot(x="poolsize", y="r2", hue='pooling_type', data=df_bar, color=None, width=0.8, showfliers = False, linewidth=3, ax=ax) sns.stripplot(x="poolsize", y="r2", hue='pooling_type', data=df_bar, dodge=True, ax=ax) sns.despine(top = True, right = True) ax.set_xlabel("Pool size", fontsize = 25) ax.set_ylabel("$R^2$", fontsize = 25) xticks = ['Split mode', '2', '3', '4', '5', '6'] ax.set_xticklabels(xticks) ax.tick_params(which='both', width=2, labelsize=25) ax.set_ylim([0.4, 1]) lines_per_boxplot = len(ax.lines) // 11 for i in range(11): color = colors[i] alpha = alphas[i] box.set_color(color) for lin in ax.lines[i * lines_per_boxplot: (i + 1) * lines_per_boxplot]: lin.set_color(color) lin.set_alpha(alpha) for i, p in enumerate(ax.patches): p.set_facecolor('None') p.set_edgecolor(color_box[i]) p.set_alpha(alpha_box[i]) for collection, color, a in zip(ax.collections, color_dot, alpha_dot): collection.set_facecolor(color) collection.set_alpha(a) ax.get_legend().remove() plt.rcParams["font.family"] = "Arial" plt.tick_params(left=True, bottom=True, width=2) plt.tight_layout() plt.show() ``` ![](https://hackmd.io/_uploads/ryoVaCra2.png) ``` df_out = df[df['poolsize']!=1] colors = ['#1f77b4', '#ff7f0e', '#2ca02c', '#d62728', '#9467bd'] fig, ax = plt.subplots(figsize = (15,3)) fig, ax = plt.subplots(5, 1, figsize = (15,15)) for poolsize in range(2, 7): aa = df_out[df_out['poolsize']==poolsize] rp = aa[aa['pooling_type']=='RP'] ep = aa[aa['pooling_type']=='EP'] sns.histplot(x=rp['r2'], binwidth=0.02, color=colors[poolsize-2], ax=ax[poolsize-2], kde=True, kde_kws={'cut': 3}, alpha=0.2) sns.histplot(x=ep['r2'], binwidth=0.02, color=colors[poolsize-2], ax=ax[poolsize-2], kde=True, kde_kws={'cut': 3}) sns.despine(top = True, right = True) ax[poolsize-2].set_xlim([0, 1]) ax[poolsize-2].set_xlabel('$R^2$', fontsize=25) ax[poolsize-2].set_ylim([0, 8]) ax[poolsize-2].set_ylabel('count', fontsize=25) ax[poolsize-2].set_title('Pool size='+str(poolsize), fontsize=25) ax[poolsize-2].tick_params(left=True, bottom=True, width=2, labelsize=25) plt.tight_layout() plt.show() ``` ![](https://hackmd.io/_uploads/SySLpAST2.png)