Closed
Description
Bug report
Bug summary
The behavior of positioning a legend outside the plot by using the figure transformation(fig.transFigure) has changed, by shortening the size of plot and leaving too much space between plot and legend.
Code for reproduction
import numpy as np
import matplotlib.pyplot as plt
# Fixing random state for reproducibility
np.random.seed(19680801)
N = 50
x = 15*np.random.rand(N)
y = 15*np.random.rand(N)
colors = np.random.rand(N)
fig, ax = plt.subplots(figsize=(8,6))
ax.scatter(x, y, c=colors, alpha=0.5, label='Scatter plot')
ax.plot([0, 15],[0, 15], color='r', linestyle='-', linewidth=2.5, label = 'Straight line')
ax.legend(bbox_to_anchor=(1, 0), loc="upper right",
bbox_transform=fig.transFigure, columnspacing=0.5, ncol=2)
fig.tight_layout()
plt.savefig(_image_name_, bbox_inches="tight")
Expected outcome
Notice the empty space between plot and the legend. This was not the case with Matplotlib version: 2.1.0
Below are the plots for the same stuff in both the versions:
Matplotlib 2.1.0:
Matplotlib version
- Operating system: Windows 10
- Matplotlib version: '2.2.2'
- Matplotlib backend: Qt5Agg or module://ipykernel.pylab.backend_inline
- Python version: Python 3.6.5 |Anaconda custom (64-bit)
- Jupyter Notebook version: 6.3.1
I have the Python installed through Anaconda and I spotted the above change after I updated my packages through Anaconda.