-2

How can I properly structure the label name of the generated graph? The code used in generating the graph is written below:

from sklearn.feature_selection import mutual_info_classif
plt.figure(figsize=(20,5))
feat_import = pd.Series(importance, new_data.columns[0:len(new_data.columns)-2])
plt.plot(feat_import, 'r')
plt.title('Best Feature Selection')
plt.ylabel('Importance')
plt.xlabel('Available features')
plt.legend([ 'importance to dependent variable'], loc='upper right')

The generated result is this:
enter image description here

I underlined with green color where I am having the issue.

One of the best ways will be to show the label name vertically rather than the horizontal display shown above. Please, how can I achieve that?

Mr. T
  • 11,960
  • 10
  • 32
  • 54
toppylawz
  • 1
  • 2

1 Answers1

0

Rotating the label names of the horizontal axis can be done via:

plt.xticks(rotation = 90) # Rotates X-Axis Ticks by 90-degrees

Minimal example:

import matplotlib.pyplot as plt
import pandas as pd

plt.figure(figsize=(6,6))
feat_import = pd.Series(data=range(10), index=['abc' * (i+1) for i in range(10)])
plt.plot(feat_import, 'r')
plt.xticks(rotation=90)
plt.show()

enter image description here

Damian
  • 79
  • 1
  • 11