Skip to content
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

Fixed categorical coloring of Contours in matplotlib #2259

Merged
merged 2 commits into from Feb 5, 2018

Conversation

philippjfr
Copy link
Member

As the title says, Contours/Polygons in matplotlib did not handle categorical values for the color_index.

@philippjfr philippjfr added type: bug Something isn't correct or isn't working tag: backend: mpl labels Jan 14, 2018
@jlstevens
Copy link
Contributor

I can't tell if this PR is ready yet, but at a glance it looks good. Happy to merge once you tell me it is ready and the tests are green.

@philippjfr
Copy link
Member Author

Can't be ready since the tests aren't green right :-) Locally it seems to pass but Travis isn't happy yet. Will try to figure this out today.

@jlstevens
Copy link
Contributor

Can't be ready since the tests aren't green right...

Could have just been unlucky with transient failures you know...

@philippjfr
Copy link
Member Author

Could have just been unlucky with transient failures you know...

The unit test I added is failing.

@philippjfr philippjfr force-pushed the mpl_contours_categorical branch 2 times, most recently from 5f74236 to cada665 Compare February 4, 2018 15:42
@@ -213,7 +213,7 @@ def values(cls, dataset, dim, expanded=True, flat=True):
if np.isscalar(values):
if not expanded:
return np.array([values])
values = np.full(len(dataset), values)
values = np.full(len(dataset), values, dtype=np.array(values).dtype)
Copy link
Member Author

@philippjfr philippjfr Feb 4, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the most bizarre bug I've come across in a long time. Before I added this dtype approach this line would error (but only on Travis), given this input:np.full(10, 'B'), saying that:

ValueError: could not convert string to float: 'B'

But internally np.full does exactly the same thing I've now done here to fix it:

def full(shape, fill_value, dtype=None, order='C'):
    if dtype is None:
        dtype = array(fill_value).dtype
    a = empty(shape, dtype, order)
    multiarray.copyto(a, fill_value, casting='unsafe')
    return a

Absolutely baffling, but it seems to work now.

@philippjfr
Copy link
Member Author

Ready now.

@jlstevens
Copy link
Contributor

Weird 'fix'!

Anyway, looks good. Merging.

@jlstevens jlstevens merged commit 263ae6a into master Feb 5, 2018
@philippjfr philippjfr added this to the 1.9.3 milestone Feb 11, 2018
@philippjfr philippjfr deleted the mpl_contours_categorical branch February 11, 2018 17:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tag: backend: mpl type: bug Something isn't correct or isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants