Open
Description
When I have very long label names and use x_tick_rotation argument the xtick labels are not aligned with the bar graph
from sklearn.datasets import load_iris
from sklearn.ensemble import RandomForestClassifier
from sklearn.tree import plot_tree
# Load the Iris dataset
X, y = load_iris(return_X_y=True)
# print(f'type(X): {type(X)} X :\n{X}')
# print(f'type(y): {type(y)} y : \n{y}')
# Train a RandomForestClassifier
model = RandomForestClassifier(random_state=42, n_estimators=10) # using 10 trees for simplicity
model.fit(X, y)
skplt.estimators.plot_feature_importances(
model, feature_names=['petal length aaaaaaaaaaaaaaaaa',
'petal width bbbbbbbbbbbbbbbbbbbb',
'sepal length cccccccccccccccccccc',
'sepal width ddddddddddddddd'],
x_tick_rotation=45
)
proposed fix
ax.set_xticks(range(len(featureNames)), featureNames,
rotation=xTickRotation, ha='right', rotation_mode='anchor')
Metadata
Metadata
Assignees
Labels
No labels