Skip to content

Commit bf5370d

Browse files
committed
Relocated test_set_clim_emits_single_callback to test_colors.py
1 parent 0c40fe1 commit bf5370d

File tree

3 files changed

+22
-24
lines changed

3 files changed

+22
-24
lines changed

lib/matplotlib/colorizer.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,9 +279,9 @@ def set_clim(self, vmin=None, vmax=None):
279279
if vmax is not None:
280280
self.norm.vmax = colors._sanitize_extrema(vmax)
281281

282-
# self.changed() will now emit a update signal if the limits are changed
282+
# emit a update signal if the limits are changed
283283
if orig_vmin_vmax != (self.norm.vmin, self.norm.vmax):
284-
self.changed()
284+
self.norm.callbacks.process('changed')
285285

286286
def get_clim(self):
287287
"""

lib/matplotlib/tests/test_colorbar.py

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818
from matplotlib.ticker import FixedLocator, LogFormatter, StrMethodFormatter
1919
from matplotlib.testing.decorators import check_figures_equal
2020

21-
import unittest.mock
22-
2321

2422
def _get_cmap_norms():
2523
"""
@@ -662,26 +660,6 @@ def test_colorbar_scale_reset():
662660
assert pcm.norm.vmax == z.max()
663661

664662

665-
def test_set_clim_emits_single_callback():
666-
data = np.array([[1, 2], [3, 4]])
667-
fig, ax = plt.subplots()
668-
image = ax.imshow(data, cmap='viridis')
669-
670-
callback = unittest.mock.Mock()
671-
image.norm.callbacks.connect('changed', callback)
672-
673-
# Initial callback count should be zero
674-
assert callback.call_count == 0
675-
676-
# Call set_clim() to update the limits
677-
image.set_clim(1, 5)
678-
679-
# Assert that only one "changed" callback is sent after calling set_clim()
680-
callback.assert_called_once()
681-
682-
plt.close(fig)
683-
684-
685663
def test_colorbar_get_ticks_2():
686664
plt.rcParams['_internal.classic_mode'] = False
687665
fig, ax = plt.subplots()

lib/matplotlib/tests/test_colors.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1605,6 +1605,26 @@ def test_norm_deepcopy():
16051605
assert norm2.vmin == norm.vmin
16061606

16071607

1608+
def test_set_clim_emits_single_callback():
1609+
data = np.array([[1, 2], [3, 4]])
1610+
fig, ax = plt.subplots()
1611+
image = ax.imshow(data, cmap='viridis')
1612+
1613+
callback = unittest.mock.Mock()
1614+
image.norm.callbacks.connect('changed', callback)
1615+
1616+
# Initial callback count should be zero
1617+
assert callback.call_count == 0
1618+
1619+
# Call set_clim() to update the limits
1620+
image.set_clim(1, 5)
1621+
1622+
# Assert that only one "changed" callback is sent after calling set_clim()
1623+
callback.assert_called_once()
1624+
1625+
plt.close(fig)
1626+
1627+
16081628
def test_norm_callback():
16091629
increment = unittest.mock.Mock(return_value=None)
16101630

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy