Search code examples
pythonmatplotlibscikit-learnvisualizationyellowbrick

how to adjust matplotlib chart figure


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?


Solution

  • 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.