2

So I'm using yellowbrick in Python, which is basically matplotlib and scikit-learn combined, to visualize some data.

My chart looks like this:

enter image description here

The labels get cut off. What I want to do is to adjust the figure so the labels on the right don't get cut off. I tried

plt.rcParams['figure.figsize'] = (10, 5)
plt.rcParams['font.size'] = 12

but when I rendered the figure, it's still cut off. Even when I save it as a png file it's still cut off. What am I missing here?

Lee Merlas
  • 430
  • 9
  • 24

1 Answers1

1

tight_layout method should solve your problem. Generally you can use it with:

fig.tight_layout()  # if fig is your figure handle

or

plt.tight_layout()  # if stated within the context of your figure

This line of code should be added after the last plotting statement just before rendering the figure.

If this does not work, please post a fully working minimal code example, as described in mcve. Afterwards I'll be able to post a fully working solution for most, if not all, cases.

JE_Muc
  • 5,403
  • 2
  • 26
  • 41
  • ok it worked after you said that part where it should be added just before plotting the figure. thanks! – Lee Merlas Jan 31 '19 at 12:42
  • 1
    You are welcome and may also upvote my answer. Yeah, if you add it before plotting the lines/scatter etc., the plot will be resized automatically and lose the tight layout. Thus you have to add it after all changes to the plot, like scaling etc., have been made. – JE_Muc Jan 31 '19 at 12:44