66
77import matplotlib .pyplot as plt
88import numpy as np
9- from matplotlib .colors import Colormap
9+ from matplotlib .colors import Colormap , Normalize
1010from matplotlib .image import imread
1111from numpy .typing import ArrayLike
1212from scipy .interpolate import griddata
@@ -67,6 +67,8 @@ class Heatmap(Plottable2D):
6767
6868 For other interpolation methods, refer to
6969 `Interpolations for imshow <https://matplotlib.org/stable/gallery/images_contours_and_fields/interpolation_methods.html>`_.
70+ norm : str or Normalize, optional
71+ Normalization of the colormap. Default is ``None``.
7072 """
7173
7274 def __init__ (
@@ -81,6 +83,7 @@ def __init__(
8183 aspect_ratio : str | float = "default" ,
8284 origin_position : str = "default" ,
8385 interpolation : str = "none" ,
86+ norm : Optional [str | Normalize ] = None ,
8487 ) -> None :
8588 """
8689 The class implements heatmaps.
@@ -119,6 +122,8 @@ def __init__(
119122
120123 For other interpolation methods, refer to
121124 `Interpolations for imshow <https://matplotlib.org/stable/gallery/images_contours_and_fields/interpolation_methods.html>`_.
125+ norm : str or Normalize, optional
126+ Normalization of the colormap. Default is ``None``.
122127 """
123128 self ._image = image
124129 self ._x_axis_range = x_axis_range
@@ -130,6 +135,7 @@ def __init__(
130135 self ._aspect_ratio = aspect_ratio
131136 self ._origin_position = origin_position
132137 self ._interpolation = interpolation
138+ self ._norm = norm
133139
134140 self ._color_bar_params : dict = {}
135141
@@ -153,6 +159,7 @@ def from_function(
153159 origin_position : str = "default" ,
154160 interpolation : str = "none" ,
155161 number_of_points : tuple [int , int ] = (50 , 50 ),
162+ norm : Optional [str | Normalize ] = None ,
156163 ) -> Self :
157164 """
158165 Creates a heatmap from a function.
@@ -194,6 +201,8 @@ def from_function(
194201 number_of_points : tuple[int, int]
195202 Number of points in the x and y coordinates.
196203 Defaults to ``(50, 50)``.
204+ norm : str or Normalize, optional
205+ Normalization of the colormap. Default is ``None``.
197206
198207 Returns
199208 -------
@@ -214,6 +223,7 @@ def from_function(
214223 aspect_ratio ,
215224 origin_position ,
216225 interpolation ,
226+ norm ,
217227 )
218228
219229 @classmethod
@@ -233,6 +243,7 @@ def from_points(
233243 origin_position : str = "default" ,
234244 interpolation : str = "none" ,
235245 number_of_points : tuple [int , int ] = (50 , 50 ),
246+ norm : Optional [str | Normalize ] = None ,
236247 ):
237248 """
238249 Creates a heatmap by interpolating unevenly distributed data points on a grid.
@@ -278,6 +289,8 @@ def from_points(
278289 number_of_points : tuple[int, int]
279290 Number of points in the x and y coordinates.
280291 Defaults to ``(50, 50)``.
292+ norm : str or Normalize, optional
293+ Normalization of the colormap. Default is ``None``.
281294
282295 Returns
283296 -------
@@ -304,6 +317,7 @@ def from_points(
304317 aspect_ratio ,
305318 origin_position ,
306319 interpolation ,
320+ norm ,
307321 )
308322
309323 @property
@@ -445,6 +459,7 @@ def _plot_element(self, axes: plt.Axes, z_order: int, **kwargs) -> None:
445459 "origin" : self ._origin_position ,
446460 "interpolation" : self ._interpolation ,
447461 "extent" : self ._xy_range ,
462+ "norm" : self ._norm ,
448463 }
449464
450465 params = {k : v for k , v in params .items () if v != "default" }
0 commit comments