0

I have these code here to create an xgboost feature importance plot with more than 40 variables :

plot_importance(xgb_model)
plt.show()

However, I got a plot with overlapping y-axis labels and it was hard to read. The figsize=() argument did not seem to work. enter image description here

Is there a way to make this plot readable?

mmmmmm
  • 53
  • 4

1 Answers1

0

Definitely go with figsize. You can see that because if you interactively change the window size you observe that the ticks labels d on't overlap anymore.

You can also change the font properties, see https://stackoverflow.com/a/11386056/13636407.

import numpy as np
import matplotlib.pyplot as plt


def plot_sin(figsize):

    x = np.linspace(0, 4 * np.pi)
    y = np.sin(x)

    fig, ax = plt.subplots(figsize=figsize)

    ax.plot(x, y)
    ax.set_yticks(np.arange(-1.15, 1.15, 0.05))
    ax.set_title(f"{figsize = }")


plot_sin(figsize=(12, 4))
plot_sin(figsize=(12, 10))

plt.show()

figsize 12 4

figsize 12 10

paime
  • 2,901
  • 1
  • 6
  • 17