Thanks to visit codestin.com
Credit goes to github.com

Skip to content

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

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

Merged
merged 2 commits into from
Aug 25, 2016

Conversation

efiring
Copy link
Member

@efiring 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 efiring force-pushed the PcolorImage_cursor branch from b52541d to ebfe81d Compare August 9, 2016 02:31
@efiring efiring added this to the 2.0 (style change major release) milestone Aug 9, 2016
@efiring
Copy link
Member Author

efiring commented Aug 9, 2016

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

@jenshnielsen
Copy link
Member

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

@efiring
Copy link
Member Author

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.

@@ -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]:
Copy link
Member

Choose a reason for hiding this comment

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

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)

Copy link
Member Author

Choose a reason for hiding this comment

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

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?

@tacaswell
Copy link
Member

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

@tacaswell
Copy link
Member

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
tacaswell added a commit that referenced this pull request Aug 25, 2016
BUG: PcolorImage handles non-contiguous arrays, provides data readout
@tacaswell
Copy link
Member

backported to v2.x as fab69a1

@efiring efiring deleted the PcolorImage_cursor branch October 24, 2021 19:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

pcolorfast results in invalid cursor data
3 participants