matplotlib
Colaboratory
Numpy & Pandas
縦線引く
matplotlib.pyplot.axvline — Matplotlib 3.7.1 documentation
axvline または axhline
plt.axvline(70, color='k', linestyle='--')
x=70 のところに黒で破線
label="姉" & plt.legend() でラベルだせるが凡例に出る
文字書く
matplotlib.text — Matplotlib 3.7.1 documentation
座標ぴったりに出てちょっと使いづらいので subplot と transform を使うやつ
matplotlibでグラフ枠から見た指定の位置にテキストを挿入する | 分析ノート
matplotlib.pyplot.annotate — Matplotlib 3.7.1 documentation
矢印も出せるけど位置指定がめんどい
日本語で
code:jp_plt.py
!pip install japanize-matplotlib
import japanize_matplotlib
subplot
matplotlib.pyplot.subplot — Matplotlib 3.7.1 documentation
plt.subplot(row, col, index) で並べていく
一部の column だけ別軸に
記事数とPVなどスケールが違うものを別に
df.plot(secondary_y=['pv']) # pv だけ右の y 軸に
DataFrame.plot.* に色々メソッドある
pandas.DataFrame.plot — pandas 1.5.3 documentation
code:plot.py
x = pd.DataFrame(np.random.normal(loc=0, scale=1, size=3000))
x.plot()
x.plot.density()
x.plot.hist(bins=100)
https://gyazo.com/f0781be99332b2d116e7d894cab6fbcc
https://gyazo.com/b16174fb727a0ab548176f3c201a9721
https://gyazo.com/7f9f762c0383b8e2d4fa40930bf97f20
論文やスライドに使う
科学技術論文に用いる図表のための matplotlib 設定 #PowerPoint - Qiita
いいね、特定の図表で設定したい場合に rc_context でこういう風にもできそう
code:rc_context.py
import matplotlib.pyplot as plt
mm = 1 / 25.4
with plt.rc_context(
{
"figure.figsize": (86 * mm, 54 * mm),
"font.size": 24,
"lines.linewidth": 2,
}
):
sns.heatmap(...)
設定可能な値は plt.rcParams.keys() で取れる、使いそうなもの
code:params.py
'axes.titlesize': 28,
'axes.labelsize': 20,
'xtick.labelsize': 18,
'ytick.labelsize': 18,
'legend.fontsize': 18,
'axes.linewidth': 1.5,
'figure.dpi': 150,
'savefig.bbox': 'tight',
mm = 1 / 25.4
# プレゼン用設定
presentation_style = {
'figure.figsize': (86 * mm, 54 * mm),
'font.size': 24,
'lines.linewidth': 3,
'axes.titlesize': 28,
'axes.labelsize': 24,
'xtick.labelsize': 20,
'ytick.labelsize': 20,
'legend.fontsize': 22,
'axes.linewidth': 2,
'savefig.bbox': 'tight'
}
#Python