###### tags: `求生指引`
# 製圖須知
[TOC]
1. 圖上任何文字開頭大寫
2. 字型
```py
sns.set_theme(font='Arial')
```
3. 縱軸橫軸格式
```py
ax[i].spines['right'].set_visible(False)
ax[i].spines['top'].set_visible(False)
ax[i].spines['left'].set_position(('outward', 10))
ax[i].spines['bottom'].set_position(('outward', 10))
ax[i].spines['bottom'].set_linewidth(3)
```
---
#### 參考色碼


["#3853a3","#eb1218","#8fb339","#FF7700","#78399f", "#472b22","#f199af","#fadf63","#5a5a5a","#7fb7be"]
參考色碼(NeuRA):

`['#fdab72', '#66afd5', '#7cd989', '#adadad']`
推薦一個可以挑選圖片上顏色的網站
https://www.ginifab.com.tw/tools/colors/color_picker_from_image.php
---
#### 統計檢定

* sns.stripplot(x="Method", y="R$^2$", data=df, size=10, hue='Method', dodge=False, alpha=0.5, ax=ax)
如果有分組 dodge=False
如果沒分組 dodge=True
可以讓點點比較均勻地散在barplot裏頭
* fig.autofmt_xdate() x軸label自動旋轉且對齊
---

```.py
import seaborn as sns
fig, ax = plt.subplots(figsize = (15,6))
sns.despine(top = True, right = True)
sns.set_theme(style='white', font_scale=2)
sns.scatterplot(x="num_units", y="r2", hue='poolsize', style='pooling_type', s=100, data=df_out, palette='deep').set(title='Correlation between $R^2$ and units count')
sns.regplot(x='num_units', y='r2', marker='pooling_type', data=df1, scatter=False, color='black', ci=None)
sns.regplot(x='num_units', y='r2', marker='pooling_type', data=df2, scatter=False, color='grey', ci=None)
CC = np.corrcoef(df2['num_units'], df2['r2'])
print(CC)
plt.legend(bbox_to_anchor=(1.05, 1), loc=2, borderaxespad=0., markerscale=2)
plt.xlabel('number of units')
plt.ylabel('$R^2$')
leg = ax.get_legend()
leg.legendHandles[-1].set_color('grey')
```
#### 迴歸線圖小巧思d(`・∀・)b
* sns.regplot、sns.lmplot可以直接畫散布圖加上迴歸線、但是其分組只能一種,以這張圖為例,需要分的組有poolsize和pooling_type,但因為同時分兩組,因此先用sns.scatterplot畫下面的散布圖,再使用sns.regplot scatter=False疊上迴歸線
#### 骨架去除
* sns.despine()裡面把要去除的部分設True
#### 圖中各種大小及白色背景
* sns.set_theme()裡的style參數可以設置背景(格子、白底...等等)。
* 圖中所有字的大小可以透過sns.theme()裡的font_scale調整,注意那是倍率,不是真的大小,所以一般設2就差不多了
* 調整圖中marker大小則在畫散布圖的函數中調整,以上圖為例,是由sns.scatterplot裡的s=100調整
#### 關於legend
* 改變legend字體大小、marker大小都要再plt.legend中調整,參數一個是fontsize、另一個是markerscale
* 但legend字體大小其實可以透過上面的set_theme就調到了,不過會有個問題是marker的大小不會被調到,所以要自己在legend中手動調整
```.py
ax.legend(markerscale=3)
```
* 以下是比較tricky的部分,如果要單獨更改marker顏色(以上圖為例我在sns.scatterplot用marker分類的pooling_type原本都是黑色,但我想要fit迴歸線的顏色,因此EP marker要調成灰色),必須使用最下面兩行
```.py
leg = ax.get_legend()
leg.legendHandles[-1].set_color('grey')
```
* leg.gendHandles會是一個legend的列表,因為我要設定的是EP的marker,因此在上列code中我取了-1來設定顏色