DAY 28
0
AI & Data

3. 折線圖、散佈圖跟柱狀圖
4. 長條圖
5. 繪製在子圖上

## 折線圖、散佈圖跟柱狀圖

`figsize`調整圖片大小，`style`改變線條的樣式，`color`改變線條的顏色，`legend`指定圖例

``````group_b.plot(y=["math score","reading score"],figsize=(20,5), style="--", color=["purple","pink"], legend=["math score","reading score"])
``````

``````plt.scatter(group_b.index ,group_b["math score"],color="purple")
``````

`plt.title()` 設置標題

`plt.xlabel()``plt.ylabel.()`分別設置x,y軸名稱

`plt.legend()`設置圖例

``````plt.hist(group_b["math score"],color="g",alpha=0.3)
plt.hist(group_b["writing score"],alpha=0.5,color="pink")
plt.title('score distribution')
plt.xlabel("score")
plt.ylabel("numbers")
``````

## 長條圖

``````race_ethnicity = df.groupby("race/ethnicity").mean()
race_ethnicity
``````

1. 直接利用整理過後的dataframe接上`.plot.bar()`

2. `.plot()`之後才在括號裡面調整參數

``````race_ethnicity.plot(kind='bar',  #圖表類型
title='scores in different group',  #標題
xlabel='gruoup',  #x軸標題
ylabel='score',  #y軸標題
legend=True,  # 顯示圖例
figsize=(10, 5))  # 設定圖表大小
``````

## 繪製在子圖上

``````fig = plt.figure(figsize=(20,10))
``````

1. `ax.title.set_text(" ")`
2. `ax.set_title(" ")`
``````#子圖一放上性別佔整體的比例
axe1.pie(numbers_of_gender, labels=type_of_gender,autopct="%0.2f%%")
axe1.title.set_text("portion of gender")

#子圖二放上各組別佔整體的比例
axe2.pie(amounts, labels=category,autopct="%0.2f%%")
axe2.title.set_text("portion of groups")

#子圖三放上各組在各科的成績平均數比較
axe3.set_title("scores on different group")
race_ethnicity.plot.bar(ax=axe3)

#子圖四看整體資料依照成績高低的分佈
axe4.hist(df["math score"],color="g",alpha=0.3) #記得調整透明度
axe4.hist(df["writing score"],alpha=0.6,color="pink")
axe4.legend(labels=score_labels)
axe4.set_title("scores distribution of all")
``````