|
| 1 | +import sys |
| 2 | + |
1 | 3 | import numpy as np
|
2 | 4 | from matplotlib.legend_handler import HandlerBase
|
3 | 5 |
|
| 6 | +if sys.version_info >= (3, 12): |
| 7 | + from typing import override |
| 8 | +else: |
| 9 | + from typing_extensions import override |
| 10 | + |
4 | 11 |
|
5 | 12 | # Define legend handler class for artists that use colormaps
|
6 | 13 | class _HandlerColorPolyCollection(HandlerBase):
|
7 | 14 | # Override create_artists to create an AxesImage resembling a colormap
|
| 15 | + @override |
8 | 16 | def create_artists(
|
9 |
| - self, legend, artist, xdescent, ydescent, width, height, fontsize, trans |
| 17 | + self, legend, orig_handle, xdescent, ydescent, width, height, fontsize, trans |
10 | 18 | ):
|
11 | 19 | from matplotlib.image import AxesImage
|
12 | 20 |
|
13 | 21 | # Obtain the Axes object of this legend
|
14 | 22 | ax = legend.axes
|
15 | 23 |
|
16 | 24 | # Obtain the colormap of the artist
|
17 |
| - cmap = artist.cmap |
| 25 | + cmap = orig_handle.cmap |
18 | 26 |
|
19 | 27 | # Create an AxesImage to contain the colormap with proper dimensions
|
20 | 28 | image = AxesImage(
|
21 |
| - ax, cmap=cmap, transform=trans, extent=[xdescent, width, ydescent, height] |
| 29 | + ax, cmap=cmap, transform=trans, extent=(xdescent, width, ydescent, height) |
22 | 30 | )
|
23 | 31 |
|
24 | 32 | # Set the data of the image
|
|
0 commit comments