BUG: PcolorImage handles non-contiguous arrays, provides data readout #6930

Merged
merged 2 commits into from Aug 25, 2016

Conversation

Projects
None yet
3 participants
Owner

efiring commented Aug 9, 2016

Closes #6905, and fixes a bug in the underlying _image.pcolor2 function. It requires that all three input arrays be contiguous, so I appended _contiguous to the converters for x and y.

To verify both the data cursor and the ability to handle non-contiguous inputs,

import numpy as np
import matplotlib.pyplot as plt

x = np.arange(4) ** 1.5
y = np.arange(3) ** 1.5

# comment out for contiguous inputs
x = x[::-1]
y = y[::-1]

z = x[:-1] - y[:-1, np.newaxis]

fig, ax = plt.subplots()
pci = ax.pcolorfast(x, y, z)
print(type(pci))
print(pci._A.shape)
print(pci._A)
print(pci._Ax)
print(pci._Ay)

plt.show()

efiring added the needs_review label Aug 9, 2016

@efiring efiring BUG: PcolorImage handles non-contiguous arrays, provides data readout
ebfe81d
Owner

efiring commented Aug 9, 2016

Lots of unrelated failures: ERROR: matplotlib.tests.test_mathtext.test_mathtext_exceptions

Owner

jenshnielsen commented Aug 9, 2016

I fixed the unrelated error on master so cycling this to rerun on current master

jenshnielsen reopened this Aug 9, 2016

Owner

efiring commented Aug 9, 2016

@mdboom, on second thought, what I characterized as a bug in _image.pcolor2 is better described as a limitation or requirement. Originally, PcolorImage was ensuring that x and y are contiguous. I broke that by indexing with [::-1] when necessary to make them increasing so I could use np.searchsorted on them. I could have added calls to np.ascontiguousarray, but judged that it was better to let _image.pcolor2 handle this. If you disagree, I will move the sanitization back out to PcolorImage.

@tacaswell tacaswell commented on the diff Aug 21, 2016

lib/matplotlib/image.py
@@ -985,6 +985,15 @@ def set_data(self, x, y, A):
self.is_grayscale = True
else:
raise ValueError("3D arrays must have RGB or RGBA as last dim")
+
+ # For efficient cursor readout, ensure x and y are increasing.
+ if x[-1] < x[0]:
@tacaswell

tacaswell Aug 21, 2016

Owner

Do we enforce that x/y are monotonic someplace else?

If we bump the minimum numpy to 1.7, searchsorted takes in a sorter kwarg which is an array with the indexes in sorted order (https://docs.scipy.org/doc/numpy/reference/generated/numpy.searchsorted.html)

@efiring

efiring Aug 21, 2016

Owner

No, we have never enforced monotonic x or y for any of the pcolor-like functions; that has implicitly been left to the user. If the user supplies non-monotonic x and/or y the plotted results will be odd, and with this PR as-is the cursor readout will sometimes be hard to predict--but the plot won't make sense anyway, so I don't see that it matters. So it seems to me that you are raising a question that is independent of this PR--should we add more input validation for this category of plot?

Owner

tacaswell commented Aug 21, 2016

I am 👍 on this modulo my concern about x/y being monotonic.

@efiring efiring DOC: add docstring for set_array; improve related docstrings in _axes.py
f1b6135
Owner

tacaswell commented Aug 25, 2016

The travis mac infrastructure is down, merging as it previously passed an the new changes are docstring only.

@tacaswell tacaswell merged commit 28b6a99 into matplotlib:master Aug 25, 2016

2 of 3 checks passed

continuous-integration/travis-ci/pr The Travis CI build is in progress
Details
continuous-integration/appveyor/pr AppVeyor build succeeded
Details
coverage/coveralls Coverage remained the same at 70.293%
Details

tacaswell removed the needs_review label Aug 25, 2016

@tacaswell tacaswell added a commit that referenced this pull request Aug 25, 2016

@tacaswell tacaswell Merge pull request #6930 from efiring/PcolorImage_cursor
BUG: PcolorImage handles non-contiguous arrays, provides data readout
fab69a1
Owner

tacaswell commented Aug 25, 2016

backported to v2.x as fab69a1

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment