Skip to content

Commit 35bbf2c

Browse files
authored
Merge pull request GraphingLib#634 from yalap13/add-norm-param-heatmap
Added norm param to Heatmap
2 parents bfa758b + 9467cbf commit 35bbf2c

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
`norm` parameter for `Heatmap`
2+
==============================
3+
Added a `norm` parameter for `Heatmap` as exists for `imshow`.

graphinglib/data_plotting_2d.py

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
import matplotlib.pyplot as plt
88
import numpy as np
9-
from matplotlib.colors import Colormap
9+
from matplotlib.colors import Colormap, Normalize
1010
from matplotlib.image import imread
1111
from numpy.typing import ArrayLike
1212
from 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

Comments
 (0)