Matplotlib,seaborn

ph
Admin (토론 | 기여)님의 2020년 5월 13일 (수) 17:02 판 (→‎use of ttf with seaborn)
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)
이동: 둘러보기, 검색

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)

use ttf in matplotlib

import matplotlib.font_manager as fm
import matplotlib.pyplot as plt

fig, ax = plt.subplots()
ax.plot(range(10))

prop = fm.FontProperties(fname='/usr/share/fonts/truetype/groovygh.ttf')
ax.set_title('This is some random font', fontproperties=prop, size=32)

plt.show()

https://stackoverflow.com/a/7728665/766330

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,...)

set title size

ref. https://stackoverflow.com/a/36222162/766330

p = sns.lineplot(ax=ax, data=data, palette='tab10', linewidth=1, dashes=dash_styles)
p.axes.set_title("EN",fontsize=50)