"Matplotlib,seaborn"의 두 판 사이의 차이
ph
잔글 (→rotate xticks) |
|||
33번째 줄: | 33번째 줄: | ||
ax = sns.boxplot(x='categories', y='oxygen', hue='target', data=df) | ax = sns.boxplot(x='categories', y='oxygen', hue='target', data=df) | ||
plt.setp(ax.get_xticklabels(), rotation=45) | plt.setp(ax.get_xticklabels(), rotation=45) | ||
+ | </source> | ||
+ | |||
+ | == Default style for more than 6 data series in seaborn == | ||
+ | ref. https://github.com/mwaskom/seaborn/issues/1513 | ||
+ | |||
+ | <source> | ||
+ | dash_styles = ["", | ||
+ | (4, 1.5), | ||
+ | (1, 1), | ||
+ | (3, 1, 1.5, 1), | ||
+ | (5, 1, 1, 1), | ||
+ | (5, 1, 2, 1, 2, 1), | ||
+ | (2, 2, 3, 1.5), | ||
+ | (1, 2.5, 3, 1.2)] | ||
+ | |||
+ | sns.relplot(..., dashes=dash_styles,...) | ||
</source> | </source> |
2020년 2월 28일 (금) 18:42 판
목차
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)
Default style for more than 6 data series in seaborn
ref. https://github.com/mwaskom/seaborn/issues/1513
dash_styles = ["",
(4, 1.5),
(1, 1),
(3, 1, 1.5, 1),
(5, 1, 1, 1),
(5, 1, 2, 1, 2, 1),
(2, 2, 3, 1.5),
(1, 2.5, 3, 1.2)]
sns.relplot(..., dashes=dash_styles,...)