0

This is what I have:

fig, ax = plt.subplots(figsize=(4, 3))
sns.histplot(my_data, ax=ax)
ax.set(ylabel='')

But this still seems to allocate the space for the y-axis label, it's only that the label itself is an empty string, which results in wasted space on the left-hand side of the image. I don't want the white space in place of the y-axis label, I really want to remove it.

foki
  • 8,624
  • 6
  • 33
  • 32
  • 1
    If you set the label spacing setting to 0, it will be closer to the left side as expected. `g=sns.histplot(...);g.set_ylabel('', labelpad=0)` – r-beginners May 25 '21 at 04:56
  • 1
    You can also try `plt.tight_layout()` which would adapt the spacing at the four sides. – JohanC May 25 '21 at 06:00

1 Answers1

1

Both answers suggested in the comments work.

One way to achieve what I want is:

fig, ax = plt.subplots(figsize=(4, 3))
sns.histplot(my_data, ax=ax)
ax.set(ylabel='')
plt.tight_layout(pad=0)

The pad parameter of tight_layout controls the size of the margin around the figure.

foki
  • 8,624
  • 6
  • 33
  • 32