Search
Duplicate

ticklabel이 너무 커서 겹친다 → 회전시키자

문제

x축의 ticklabel들이 너무 길어서 서로 겹친다.
import seaborn as sns flierprops = { 'marker': '.', 'markersize': 3, } fig = plt.figure(figsize=(1, 1.5)) ax = fig.add_subplot(111) p = sns.boxplot( data=iris_full, x='target', y='sepal length (cm)', hue='condition', hue_order=['Bad', 'Good'], showfliers=False, flierprops=flierprops, ax=ax ) ax.legend(loc='center left', bbox_to_anchor=(1.01, 0.5))
Python
복사

해결

ax.set_xticklabelsrotation

import seaborn as sns flierprops = { 'marker': '.', 'markersize': 3, } fig = plt.figure(figsize=(1, 1.5)) ax = fig.add_subplot(111) p = sns.boxplot( data=iris_full, x='target', y='sepal length (cm)', hue='condition', hue_order=['Bad', 'Good'], showfliers=False, flierprops=flierprops, ax=ax ) ax.legend(loc='center left', bbox_to_anchor=(1.01, 0.5)) # 해결: xticklabel들을 회전시킨다. ax.set_xticklabels(ax.get_xticklabels(), rotation=33)
Python
복사

(선택) 텍스트 끝 부분을 tick과 정렬하고 싶으면 ha='right'

import seaborn as sns flierprops = { 'marker': '.', 'markersize': 3, } fig = plt.figure(figsize=(1, 1.5)) ax = fig.add_subplot(111) p = sns.boxplot( data=iris_full, x='target', y='sepal length (cm)', hue='condition', hue_order=['Bad', 'Good'], showfliers=False, flierprops=flierprops, ax=ax ) ax.legend(loc='center left', bbox_to_anchor=(1.01, 0.5)) # 해결: xticklabel들을 회전시킨다. ax.set_xticklabels(ax.get_xticklabels(), rotation=33, ha='right')
Python
복사