-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Legend placement bug #1235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Fantastic simple, reproducible case. The problem is that the best placement only takes |
@pelson Thanks for that info. Given your comment, would it be too presumptuous to say we'd also see this behaviour for text and arrows under the legend? Perhaps Edit: Grammar. |
In my eyes, that would make best better... |
So I'm trying to fix this just for the for handle in ax.collections:
paths = handle.get_paths()
transforms = handle.get_transforms()
for p, t in zip(paths, transforms):
box = p.get_extents(transform=t)
print(box) There are 3
Any idea what's going on? Did I do something silly? |
The way this code has been written, yes, there should be 3 collections. In most cases though, one would plot the 3 points in one PathCollection i.e. My knowledge of Collections is very limited, but you may be interested in the |
Aha! Thank you. So a |
Easy when you put it like that :-) |
Hey, I took a crack at solving this bug along with some help from @abalmeida7 and @ShaiMitchell @@ -716,6 +716,7 @@ class Legend(Artist):
ax = self.parent
bboxes = []
lines = []
+ points = []
for handle in ax.lines:
assert isinstance(handle, Line2D)
@@ -734,12 +735,15 @@ class Legend(Artist):
transform = handle.get_transform()
bboxes.append(handle.get_path().get_extents(transform))
+ for handle in ax.collections:
+ points.append(handle._offsets)
+
try:
vertices = np.concatenate([l.vertices for l in lines])
except ValueError:
vertices = np.array([])
- return [vertices, bboxes, lines]
+ return [vertices, bboxes, lines, points]
def draw_frame(self, b):
'b is a boolean. Set draw frame to b'
@@ -896,7 +900,7 @@ class Legend(Artist):
# should always hold because function is only called internally
assert self.isaxes
- verts, bboxes, lines = self._auto_legend_data()
+ verts, bboxes, lines, points = self._auto_legend_data()
bbox = Bbox.from_bounds(0, 0, width, height)
if consider is None:
@@ -927,12 +927 @@ class Legend(Artist):
if line.intersects_bbox(legendBox):
badness += 1
+ for point in points:
+ val = self.parent.transData.transform(np.vstack(point[0]).T)
+ if legendBox.count_contains(val):
+ badness += 1
ox, oy = l, b
if badness == 0:
return ox, oy
candidates.append((badness, (l, b)))
|
@wmak Could you put that in a PR? It make reviewing proposed changes much easier (and lets the CI server have at it). |
This script produces a legend that covers the red point:
The text was updated successfully, but these errors were encountered: