Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Reverted a previous change to artist transform setting. Fixes legend bug. #1176

Merged
merged 1 commit into from

4 participants

@pelson
Collaborator

On master, the following code fails to put the markers in a legend in the correct place:

import matplotlib.pyplot as plt

plt.subplot(222)

plt.subplot(223)
plt.scatter(range(10), range(10), label='foo')
plt.legend()

plt.show()

It turns out this is a result of a previous pull request of mine (#1090). This PR fixes this regression (and adds a suitable test). I will milestone this for 1.2 as it is a pretty critical bug fix.

@WeatherGod
Collaborator

That's really strange. I would have considered the "t is not None" test as being superior to blindly setting the boolean to True. Maybe some code somewhere is fiddling around with the _transform attribute directly when it shouldn't?

@pelson
Collaborator

That's really strange. I would have considered the "t is not None" test as being superior to blindly setting the boolean to True

Me too! The Artist._transformSet attribute is used by the Artist.is_transform_set method. The only place this is used is in axes.py and offsetbox.py. I believe the issue is in offsetbox, which checks is_transform_set and if it isn't, adds a generic transform (from offsetbox.DrawingArea.get_transform()). All this stuff is pretty deep in mpl, and I am a little hesitant to change some of this stuff, hence I reverted my own change.

@travisbot

This pull request fails (merged 654b2922 into cf7618c).

@mdboom
Owner

Thanks for finding this and tracking this down. I think what's not clear is that a transform of None is set, that's equivalent to an identity transform, and should be treated as an explicit transform having been set as far as the offsetbox is concerned. I think this change is correct, though I haven't run it against the test suite to see if it produces additional failures.

@pelson
Collaborator

though I haven't run it against the test suite to see if it produces additional failures

You were right to have your suspicions. I do get failures as a result of this. Back to the drawing board... might not find a solution to this until tomorrow.

@travisbot

This pull request fails (merged 4965b5df into cf7618c).

@pelson
Collaborator

Ok. I have solved this issue the proper way. I did a lot of reading of the legend code (phew, its not particularly easy to follow), found the problem (the transforms weren't being set correctly) and fixed a couple of typos.

Unfortunately, my editor had a setting enabled to fix the whitespace problems automatically, which adds a little bit of noise to this PR. It wouldn't be unreasonable to ask me to revert them, but I am keeping them for now as they do improve the overall readability of the code (and hence my sanity while I was debugging this).

@mdboom
Owner

The fancy_test fails for me due to text differences. I think either the freetype version needs to be restricted (not ideal), or the text needs to be changed to use characters that don't exhibit these differences.

imgur

@pelson
Collaborator

or the text needs to be changed to use characters that don't exhibit these differences

@mdboom any advice on how best to go about this?

@mdboom
Owner

Maybe the best/easiest thing to do is to just take the text out -- the legend should layout good enough for the purposes of the test without it.

@mdboom mdboom merged commit 3bfb6b8 into matplotlib:master

1 check failed

Details default The Travis build failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 7, 2012
  1. @pelson
Something went wrong with that request. Please try again.