Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit5059e7e

Browse files
committed
Warn via logging, add test
1 parent1290594 commit5059e7e

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

‎lib/matplotlib/image.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
frommathimportceil
1515
importos
16-
importwarnings
16+
importlogging
1717

1818
importnumpyasnp
1919

@@ -35,6 +35,8 @@
3535
frommatplotlib.transformsimport (Affine2D,BboxBase,Bbox,BboxTransform,
3636
IdentityTransform,TransformedBbox)
3737

38+
_log=logging.getLogger(__name__)
39+
3840
# map interpolation strings to module constants
3941
_interpd_= {
4042
'none':_image.NEAREST,# fall back to nearest when not supported
@@ -618,7 +620,7 @@ def set_data(self, A):
618620
# making reliable interpretation impossible.
619621
high=255ifnp.issubdtype(self._A.dtype,np.integer)else1
620622
ifself._A.min()<0orhigh<self._A.max():
621-
warnings.warn(
623+
_log.warn(
622624
'Clipping input data to the valid range for imshow with '
623625
'RGB data ([0..1] for floats or [0..255] for integers).'
624626
)

‎lib/matplotlib/tests/test_image.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ def test_minimized_rasterized():
602602
deftest_load_from_url():
603603
req=six.moves.urllib.request.urlopen(
604604
"http://matplotlib.org/_static/logo_sidebar_horiz.png")
605-
Z=plt.imread(req)
605+
plt.imread(req)
606606

607607

608608
@image_comparison(baseline_images=['log_scale_image'],
@@ -795,6 +795,17 @@ def test_imshow_no_warn_invalid():
795795
assertlen(warns)==0
796796

797797

798+
@pytest.mark.parametrize('as_float', [True,False])
799+
deftest_imshow_logs_when_clipping_invalid_rgb(as_float,caplog):
800+
arr=np.arange(300).reshape((10,10,3))
801+
ifas_float:
802+
arr=arr/255
803+
fig=plt.figure()
804+
ax=fig.add_subplot(111)
805+
ax.imshow(arr)
806+
assert'Clipping input data to the valid range for imshow'incaplog.text
807+
808+
798809
@image_comparison(baseline_images=['imshow_flatfield'],
799810
remove_text=True,style='mpl20',
800811
extensions=['png'])

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp