In the following code, I generate a scatterplot where the legend is manually placed:
#!/usr/bin/env python3
import pandas as pd
import matplotlib.pyplot as plt
import numpy as np
frame = frame = pd.DataFrame({"x": [1, 2, 3, 4], "y": [4, 3, 2, 1]})
ax = frame.plot.scatter(x="x", y="y", label="dots")
plt.savefig("dots.pdf")
for y in [0.6, 0.7, 0.8]:
ax.legend(bbox_to_anchor=(0.5, y), bbox_transform=ax.transAxes)
plt.savefig("dots_{}.png".format(y))
It looks like the legend does not obey the placement instructions when it would make it hide a point:
Is there a way to avoid this? I mean, how to really force the placement of the legend?