Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5c05183

Browse filesBrowse files
committed
fix heatmap cmap and vmin vmax, add heatmap tests
1 parent 430f513 commit 5c05183
Copy full SHA for 5c05183

File tree

Expand file treeCollapse file tree

7 files changed

+179
-21
lines changed
Filter options
Expand file treeCollapse file tree

7 files changed

+179
-21
lines changed

‎examples/desktop/heatmap/__init__.py

Copy file name to clipboardExpand all lines: examples/desktop/heatmap/__init__.py
Whitespace-only changes.

‎examples/desktop/heatmap/heatmap.py

Copy file name to clipboard
+37Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
"""
2+
Simple Heatmap
3+
==============
4+
Example showing how to plot a heatmap
5+
"""
6+
7+
# test_example = true
8+
9+
import fastplotlib as fpl
10+
import numpy as np
11+
12+
plot = fpl.Plot()
13+
# to force a specific framework such as glfw:
14+
# plot = fpl.Plot(canvas="glfw")
15+
16+
xs = np.linspace(0, 1_000, 20_000)
17+
18+
sine = np.sin(xs)
19+
cosine = np.cos(xs)
20+
21+
# alternating sines and cosines
22+
data = np.zeros((10_000, 20_000), dtype=np.float32)
23+
data[::2] = sine
24+
data[1::2] = cosine
25+
26+
# plot the image data
27+
heatmap_graphic = plot.add_heatmap(data=data, name="heatmap")
28+
29+
plot.show()
30+
31+
plot.canvas.set_logical_size(1500, 1500)
32+
33+
plot.auto_scale()
34+
35+
if __name__ == "__main__":
36+
print(__doc__)
37+
fpl.run()
+39Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
"""
2+
Heatmap change cmap
3+
===================
4+
Change the cmap of a heatmap
5+
"""
6+
7+
# test_example = true
8+
9+
import fastplotlib as fpl
10+
import numpy as np
11+
12+
plot = fpl.Plot()
13+
# to force a specific framework such as glfw:
14+
# plot = fpl.Plot(canvas="glfw")
15+
16+
xs = np.linspace(0, 1_000, 20_000)
17+
18+
sine = np.sin(xs)
19+
cosine = np.cos(xs)
20+
21+
# alternating sines and cosines
22+
data = np.zeros((10_000, 20_000), dtype=np.float32)
23+
data[::2] = sine
24+
data[1::2] = cosine
25+
26+
# plot the image data
27+
heatmap_graphic = plot.add_heatmap(data=data, name="heatmap")
28+
29+
plot.show()
30+
31+
plot.canvas.set_logical_size(1500, 1500)
32+
33+
plot.auto_scale()
34+
35+
heatmap_graphic.cmap = "viridis"
36+
37+
if __name__ == "__main__":
38+
print(__doc__)
39+
fpl.run()
+41Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
"""
2+
Heatmap change data
3+
===================
4+
Change the data of a heatmap
5+
"""
6+
7+
# test_example = true
8+
9+
import fastplotlib as fpl
10+
import numpy as np
11+
12+
plot = fpl.Plot()
13+
# to force a specific framework such as glfw:
14+
# plot = fpl.Plot(canvas="glfw")
15+
16+
xs = np.linspace(0, 1_000, 20_000)
17+
18+
sine = np.sin(xs)
19+
cosine = np.cos(xs)
20+
21+
# alternating sines and cosines
22+
data = np.zeros((10_000, 20_000), dtype=np.float32)
23+
data[::2] = sine
24+
data[1::2] = cosine
25+
26+
# plot the image data
27+
heatmap_graphic = plot.add_heatmap(data=data, name="heatmap")
28+
29+
plot.show()
30+
31+
plot.canvas.set_logical_size(1500, 1500)
32+
33+
plot.auto_scale()
34+
35+
heatmap_graphic.data[:5_000] = sine
36+
heatmap_graphic.data[5_000:] = cosine
37+
38+
39+
if __name__ == "__main__":
40+
print(__doc__)
41+
fpl.run()
+40Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
"""
2+
Heatmap change vmin vmax
3+
========================
4+
Change the vmin vmax of a heatmap
5+
"""
6+
7+
# test_example = true
8+
9+
import fastplotlib as fpl
10+
import numpy as np
11+
12+
plot = fpl.Plot()
13+
# to force a specific framework such as glfw:
14+
# plot = fpl.Plot(canvas="glfw")
15+
16+
xs = np.linspace(0, 1_000, 20_000)
17+
18+
sine = np.sin(xs)
19+
cosine = np.cos(xs)
20+
21+
# alternating sines and cosines
22+
data = np.zeros((10_000, 20_000), dtype=np.float32)
23+
data[::2] = sine
24+
data[1::2] = cosine
25+
26+
# plot the image data
27+
heatmap_graphic = plot.add_heatmap(data=data, name="heatmap")
28+
29+
plot.show()
30+
31+
plot.canvas.set_logical_size(1500, 1500)
32+
33+
plot.auto_scale()
34+
35+
heatmap_graphic.cmap.vmin = -0.5
36+
heatmap_graphic.cmap.vmax = 0.5
37+
38+
if __name__ == "__main__":
39+
print(__doc__)
40+
fpl.run()

‎fastplotlib/graphics/_features/_colors.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/_features/_colors.py
+22-1Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -401,8 +401,29 @@ class HeatmapCmapFeature(ImageCmapFeature):
401401
"""
402402

403403
def _set(self, cmap_name: str):
404+
# in heatmap we use one material for all ImageTiles
404405
self._parent._material.map.data[:] = make_colors(256, cmap_name)
405406
self._parent._material.map.update_range((0, 0, 0), size=(256, 1, 1))
406-
self.name = cmap_name
407+
self._name = cmap_name
407408

408409
self._feature_changed(key=None, new_data=self.name)
410+
411+
@property
412+
def vmin(self) -> float:
413+
"""Minimum contrast limit."""
414+
return self._parent._material.clim[0]
415+
416+
@vmin.setter
417+
def vmin(self, value: float):
418+
"""Minimum contrast limit."""
419+
self._parent._material.clim = (value, self._parent._material.clim[1])
420+
421+
@property
422+
def vmax(self) -> float:
423+
"""Maximum contrast limit."""
424+
return self._parent._material.clim[1]
425+
426+
@vmax.setter
427+
def vmax(self, value: float):
428+
"""Maximum contrast limit."""
429+
self._parent._material.clim = (self._parent._material.clim[0], value)

‎fastplotlib/graphics/image.py

Copy file name to clipboardExpand all lines: fastplotlib/graphics/image.py
-20Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -480,26 +480,6 @@ def __init__(
480480
# set it with the actual data
481481
self.data = data
482482

483-
@property
484-
def vmin(self) -> float:
485-
"""Minimum contrast limit."""
486-
return self._material.clim[0]
487-
488-
@vmin.setter
489-
def vmin(self, value: float):
490-
"""Minimum contrast limit."""
491-
self._material.clim = (value, self._material.clim[1])
492-
493-
@property
494-
def vmax(self) -> float:
495-
"""Maximum contrast limit."""
496-
return self._material.clim[1]
497-
498-
@vmax.setter
499-
def vmax(self, value: float):
500-
"""Maximum contrast limit."""
501-
self._material.clim = (self._material.clim[0], value)
502-
503483
def set_feature(self, feature: str, new_data: Any, indices: Any):
504484
pass
505485

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.