Home > Enterprise >  Change Figure Size in Matplotlib
Change Figure Size in Matplotlib

Time:05-05

This is my code and I want to make the plot bigger so it's easier to read. Here I'm trying to get feature importance based on mean decrease in impurity. I'm getting some output but since my barplot has 63 bins, I want it much bigger. I tried everything that is commented. Can someone please suggest how can I make this bar plot more readable? enter image description here

import pandas as pd
from matplotlib.pyplot import figure

# fig.set_figheight(20)
# fig.set_figwidth(20)
#plt_1 = plt.figure(figsize=(20, 15), dpi = 100)

forest_importances = pd.Series(importances, index=feature_names)
fig, ax = plt.subplots()
forest_importances.plot.bar(yerr=std, ax=ax)
ax.set_title("Feature importances using MDI")
ax.set_ylabel("Mean decrease in impurity")

# fig = plt.figure()

fig.tight_layout()
plt.show()

CodePudding user response:

Use fig.set_size_inches before plt.show():

width = 8
height = 6
fig.set_size_inches(width, height)
  • Related