LoginSignup
0
0

More than 1 year has passed since last update.

Seaborn箱ひげ図の横軸を10のN乗表示にする

Last updated at Posted at 2022-05-12

箱ひげ図の横軸が数値で、1000000, 2000000, ... などとなっている場合に、1, 2, ... × 10^6 と表示したい。どうやらScalarFormatterではできないっぽい。

ここを参考に、seabornで自動設定されるx軸ラベルを取得して数値に変換し、1000000で割った。

python
import matplotlib.pyplot as plt
import seaborn as sns
import textwrap

fig, ax = plt.subplots(figsize=(8, 6))

sns.boxplot(x="Density", y="Ratio", data=df, color='lightgray')
texts = [textwrap.fill(t.get_text(), 10)  for t in ax.get_xticklabels()]
xlabels = [int(t)/10**6 for t in texts]
ax.set_xticklabels(xlabels) 
ax.set_xlabel("Density [$10^6$ cells/mL]")

こんな感じ(データはお見せできないのでx軸のみ)。
スクリーンショット 2022-05-12 17.29.42.png

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0