mirror of
https://github.com/rasterio/rasterio.git
synced 2025-12-08 17:36:12 +00:00
Don't squeeze 2-D arrays when plotting (#3008)
* Don't squeeze 2-D arrays when plotting. Resolves #3007 * Update change log
This commit is contained in:
parent
a5e8fd02f1
commit
34b0d1b34d
@ -31,6 +31,7 @@ New Features:
|
||||
|
||||
Bug fixes:
|
||||
|
||||
- Avoid squeezing narrow 2-D arrays to 1-D (#3008).
|
||||
- Operations on closed MemoryFile and ZipMemoryFile objects now raise
|
||||
ValueError as with other Python file objects (#2870, #).
|
||||
- Delay clamping of I/O windows until just before GDAL methods calls to improve
|
||||
|
||||
@ -111,9 +111,10 @@ def show(source, with_bounds=True, contour=False, contour_label_kws=None,
|
||||
arr = source.read(1, masked=True)
|
||||
else:
|
||||
# The source is a numpy array reshape it to image if it has 3+ bands
|
||||
source = np.ma.squeeze(source)
|
||||
if source.ndim >= 3:
|
||||
source = np.ma.squeeze(source)
|
||||
|
||||
if len(source.shape) >= 3:
|
||||
if source.ndim >= 3:
|
||||
arr = reshape_as_image(source)
|
||||
else:
|
||||
arr = source
|
||||
|
||||
@ -301,3 +301,13 @@ def test_plot_normalize():
|
||||
a = np.linspace(1, 6, 10)
|
||||
b = adjust_band(a, 'linear')
|
||||
np.testing.assert_array_almost_equal(np.linspace(0, 1, 10), b)
|
||||
|
||||
|
||||
def test_issue3007():
|
||||
"""Don't squeeze further than 2D."""
|
||||
with rasterio.open('tests/data/RGB.byte.tif') as src:
|
||||
arr = src.read(1)[0:1, :]
|
||||
assert arr.shape == (1, 791)
|
||||
show(arr)
|
||||
fig = plt.gcf()
|
||||
plt.close(fig)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user