1515
1616from matplotlib import (
1717 _api , artist , cbook , colors as mcolors , lines , text as mtext ,
18- path as mpath , rcParams )
18+ path as mpath , rcParams , colorizer as mcolorizer )
1919from matplotlib .collections import (
2020 Collection , LineCollection , PolyCollection , PatchCollection , PathCollection )
2121from matplotlib .patches import Patch
2222from . import proj3d
23+ import collections
2324
2425
2526def _norm_angle (a ):
@@ -1712,9 +1713,10 @@ def norm(x):
17121713 return colors
17131714
17141715
1715- class VoxelDict (dict ):
1716+ class VoxelDict (mcolorizer ._ColorbarMappable ,
1717+ collections .abc .MutableMapping ):
17161718 """
1717- A dictionary subclass indexed by coordinate, where ``faces[i, j, k]``
1719+ A mapping indexed by coordinate, where ``faces[i, j, k]``
17181720 is a `.Poly3DCollection` of the faces drawn for the voxel
17191721 ``filled[i, j, k]``. If no faces were drawn for a given voxel,
17201722 either because it was not asked to be drawn, or it is fully
@@ -1724,33 +1726,37 @@ class VoxelDict(dict):
17241726 for a colorbar.
17251727 """
17261728
1727- def __init__ (self , axes , colorizer ):
1729+ def __init__ (self , colorizer , axes ):
17281730 """
17291731 Parameters
17301732 ----------
1733+ colorizer : `mpl.colorizer.Colorizer`
1734+ The colorizer uset to convert data to color.
1735+
17311736 axes : `mplot3d.axes3d.Axes3D`
17321737 The axes the voxels are contained in.
17331738
1734- colorizer : `mpl.colorizer.Colorizer`
1735- The colorizer uset to convert data to color.
17361739 """
1737- super ().__init__ (self )
1740+
1741+ super ().__init__ (colorizer )
17381742 self .axes = axes
1739- self .colorizer = colorizer
1740- self ._callbacks = cbook .CallbackRegistry (signals = ["changed" ])
17411743 self ._A = None
1744+ self ._mapping = dict ()
1745+
1746+ def __getitem__ (self , key ):
1747+ return self ._mapping [key ]
17421748
1743- @property
1744- def cmap (self ):
1745- return self .colorizer .cmap
1749+ def __setitem__ (self , key , val ):
1750+ self ._mapping [key ] = val
17461751
1747- @property
1748- def norm (self ):
1749- return self .colorizer .norm
1752+ def __delitem__ (self , key ):
1753+ del self ._mapping [key ]
17501754
1751- @property
1752- def callbacks (self ):
1753- return self ._callbacks
1755+ def __len__ (self ):
1756+ return len (self ._mapping )
1757+
1758+ def __iter__ (self ):
1759+ return reversed (self ._mapping )
17541760
17551761 def get_array (self ):
17561762 """
@@ -1772,72 +1778,3 @@ def set_array(self, A):
17721778 self ._A = A
17731779 for a , k in zip (A , self .keys ()):
17741780 self [k ].set_array (a )
1775-
1776- def add_callback (self , func ):
1777- """
1778- Add a callback function that will be called whenever one of the
1779- `.Artist`'s properties changes.
1780-
1781- Parameters
1782- ----------
1783- func : callable
1784- The callback function. It must have the signature::
1785-
1786- def func(artist: Artist) -> Any
1787-
1788- where *artist* is the calling `.Artist`. Return values may exist
1789- but are ignored.
1790-
1791- Returns
1792- -------
1793- int
1794- The observer id associated with the callback. This id can be
1795- used for removing the callback with `.remove_callback` later.
1796-
1797- See Also
1798- --------
1799- remove_callback
1800- """
1801- # Wrapping func in a lambda ensures it can be connected multiple times
1802- # and never gets weakref-gc'ed.
1803- return self ._callbacks .connect ("changed" , lambda : func (self ))
1804-
1805- def remove_callback (self , oid ):
1806- """
1807- Remove a callback based on its observer id.
1808-
1809- See Also
1810- --------
1811- add_callback
1812- """
1813- self ._callbacks .disconnect (oid )
1814-
1815- def changed (self , * args ):
1816- """
1817- Call all of the registered callbacks.
1818-
1819- This function is triggered internally when a property is changed.
1820-
1821- See Also
1822- --------
1823- add_callback
1824- remove_callback
1825- """
1826- self ._callbacks .process ("changed" )
1827-
1828- def get_alpha (self ):
1829- return 1.0
1830-
1831- def autoscale (self , A ):
1832- """
1833- Autoscale the scalar limits on the norm instance using the
1834- current array
1835- """
1836- self .colorizer .autoscale (A )
1837-
1838- def autoscale_None (self ):
1839- """
1840- Autoscale the scalar limits on the norm instance using the
1841- current array, changing only limits that are None
1842- """
1843- self .colorizer .autoscale_None (self ._A )
0 commit comments