Solution Timeline

All versions (edits) of solutions to Python matplotlib legend and title are being cliped appear below in the order they were created. Comments that appear under revisions were those created when that particular revision was current.

To see the revision history of a single solution (with diffs), click on the solution number (ie. "#1") in the upper right corner of a solution revision below.

← Bounty Expand all edits

Hello broadreach,

Instead of using tight layout, you can scale the figure to accommodate other elements.
The new script can be found here.

Let me know if you need anything more.

Thanks,
Vladimir

You have to put fig.tight_layout() after all changes to the plot, just before show() or save(), like so:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

ax.scatter( [50, 50],[10,40], c='blue', s=200, label="#1 cats and dogs")
ax.scatter([100,100], [30,60], c='green', s=200, label="#2 pigs in mud" )
ax.scatter([30,30], [30,60], c='yellow', s=200, label="#3 nothing good")
ax.legend(bbox_to_anchor=(1.01,1), borderaxespad = 0,fontsize=8 )

plt.title('Scatter')
plt.xlabel('categories')
plt.ylabel('values')

fig.tight_layout() # <<<

plt.show()

You have to put fig.tight_layout() after all changes to the plot, just before show(), like so:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

ax.scatter( [50, 50],[10,40], c='blue', s=200, label="#1 cats and dogs")
ax.scatter([100,100], [30,60], c='green', s=200, label="#2 pigs in mud" )
ax.scatter([30,30], [30,60], c='yellow', s=200, label="#3 nothing good")
ax.legend(bbox_to_anchor=(1.01,1), borderaxespad = 0,fontsize=8 )

plt.title('Scatter')
plt.xlabel('categories')
plt.ylabel('values')

fig.tight_layout() # <<<

plt.show()

You have to put fig.tight_layout() after all changes to the plot, just before show(), like so:

import matplotlib.pyplot as plt

fig, ax = plt.subplots()

ax.scatter( [50, 50],[10,40], c='blue', s=200, label="#1 cats and dogs")
ax.scatter([100,100], [30,60], c='green', s=200, label="#2 pigs in mud" )
ax.scatter([30,30], [30,60], c='yellow', s=200, label="#3 nothing good")
ax.legend(bbox_to_anchor=(1.01,1), borderaxespad = 0,fontsize=8 )

plt.title('Scatter')
plt.xlabel('categories')
plt.ylabel('values')

fig.tight_layout() # <<<

plt.show()

Also, as documented in the Tight Layout Guide:

Note that matplotlib.pyplot.tight_layout() will only adjust the subplot params when it is called. In order to perform this adjustment each time the figure is redrawn, you can call fig.set_tight_layout(True), or, equivalently, set rcParams["figure.autolayout"] (default: False) to True.
Winning solution