"Matplotlib,seaborn"의 두 판 사이의 차이
ph
잔글 |
|||
11번째 줄: | 11번째 줄: | ||
== use of ttf with seaborn == | == use of ttf with seaborn == | ||
− | ref. https://matplotlib.org/gallery/api/font_file.html | + | ref. https://matplotlib.org/gallery/api/font_file.html , https://seaborn.pydata.org/generated/seaborn.set.html |
<source> | <source> | ||
import os | import os | ||
25번째 줄: | 25번째 줄: | ||
p = sns.lineplot(ax=ax, data=data, palette='tab10', linewidth=1, dashes=dash_styles) | p = sns.lineplot(ax=ax, data=data, palette='tab10', linewidth=1, dashes=dash_styles) | ||
plt.setp(p.get_xticklabels(), rotation=90, fontproperties=prop) | plt.setp(p.get_xticklabels(), rotation=90, fontproperties=prop) | ||
+ | </source> | ||
+ | |||
+ | |||
+ | == rotate xticks == | ||
+ | ref. https://www.drawingfromdata.com/how-to-rotate-axis-labels-in-seaborn-and-matplotlib , https://stackoverflow.com/questions/44954123/rotate-xtick-labels-in-seaborn-boxplot | ||
+ | <source> | ||
+ | ax = sns.boxplot(x='categories', y='oxygen', hue='target', data=df) | ||
+ | plt.setp(ax.get_xticklabels(), rotation=45) | ||
</source> | </source> |
2020년 2월 28일 (금) 18:41 판
xticks on top
ref. https://matplotlib.org/3.1.3/gallery/ticks_and_spines/tick_xlabel_top.html
import matplotlib.pyplot as plt
import numpy as np
plt.rcParams['xtick.bottom'] = plt.rcParams['xtick.labelbottom'] = False
plt.rcParams['xtick.top'] = plt.rcParams['xtick.labeltop'] = True
use of ttf with seaborn
ref. https://matplotlib.org/gallery/api/font_file.html , https://seaborn.pydata.org/generated/seaborn.set.html
import os
from matplotlib import font_manager as fm, rcParams
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
fpath = os.path.join(rcParams["datapath"], "fonts/ttf/cmr10.ttf")
prop = fm.FontProperties(fname=fpath)
p = sns.lineplot(ax=ax, data=data, palette='tab10', linewidth=1, dashes=dash_styles)
plt.setp(p.get_xticklabels(), rotation=90, fontproperties=prop)
rotate xticks
ref. https://www.drawingfromdata.com/how-to-rotate-axis-labels-in-seaborn-and-matplotlib , https://stackoverflow.com/questions/44954123/rotate-xtick-labels-in-seaborn-boxplot
ax = sns.boxplot(x='categories', y='oxygen', hue='target', data=df)
plt.setp(ax.get_xticklabels(), rotation=45)