@@ -429,7 +429,7 @@ def plot_precision_recall_curve(y_true, y_probas, title='Precision-Recall Curve'
429429
430430
431431def plot_feature_importances (clf , title = 'Feature Importance' , feature_names = None ,
432- max_num_features = 20 , order = 'descending' , ax = None ,
432+ max_num_features = 20 , order = 'descending' , x_tick_rotation = 0 , ax = None ,
433433 figsize = None , title_fontsize = "large" , text_fontsize = "medium" ):
434434 """Generates a plot of a classifier's feature importances.
435435
@@ -447,6 +447,9 @@ def plot_feature_importances(clf, title='Feature Importance', feature_names=None
447447 order ('ascending', 'descending', or None, optional): Determines the order in which the
448448 feature importances are plotted. Defaults to 'descending'.
449449
450+ x_tick_rotation (int, optional): Rotates x-axis tick labels by the specified angle. This is
451+ useful in cases where there are numerous categories and the labels overlap each other.
452+
450453 ax (:class:`matplotlib.axes.Axes`, optional): The axes upon which to plot
451454 the learning curve. If None, the plot is drawn on a new set of axes.
452455
@@ -522,7 +525,7 @@ def plot_feature_importances(clf, title='Feature Importance', feature_names=None
522525 color = 'r' , align = 'center' )
523526
524527 ax .set_xticks (range (max_num_features ))
525- ax .set_xticklabels (feature_names [:max_num_features ])
528+ ax .set_xticklabels (feature_names [:max_num_features ], rotation = x_tick_rotation )
526529 ax .set_xlim ([- 1 , max_num_features ])
527530 ax .tick_params (labelsize = text_fontsize )
528531 return ax
0 commit comments