Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

estimators.plot_feature_importances x_tick_rotation is misaligned #121

Open
aedavids opened this issue May 13, 2024 · 0 comments
Open

estimators.plot_feature_importances x_tick_rotation is misaligned #121

aedavids opened this issue May 13, 2024 · 0 comments

Comments

@aedavids
Copy link

When I have very long label names and use x_tick_rotation argument the xtick labels are not aligned with the bar graph
Screen Shot 2024-05-12 at 5 04 57 PM

ref: ref: https://scikit-plot.readthedocs.io/en/stable/estimators.html#scikitplot.estimators.plot_feature_importances

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')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant