Skip to content

Commit 4ef2dae

Browse files
committed
Added support for colormap inversion
1 parent 738af55 commit 4ef2dae

File tree

16 files changed

+431
-311
lines changed

16 files changed

+431
-311
lines changed

.coveragerc

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,10 @@ omit =
99
*/qwt/*
1010
*/guidata/*
1111

12-
exclude_lines =
12+
[report]
13+
exclude_also =
14+
def __repr__
15+
raise AssertionError
16+
raise NotImplementedError
1317
if __name__ == .__main__.:
14-
if TYPE_CHECKING:
18+
if TYPE_CHECKING:

CHANGELOG.md

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
# Changelog #
22

3-
## Version 2.2.1 ##
3+
## Version 2.3.0 ##
44

5-
Changes:
5+
In this release, test coverage is 75%.
6+
7+
New features:
8+
9+
* Added support for colormap inversion:
10+
* The user can now invert the colormap of an image item:
11+
* From the image parameters dialog ("Invert colormap" checkbox)
12+
* From the plot context menu (right-click on the image item)
13+
* `BaseImageItem.set_color_map` method takes a new `invert` parameter (which
14+
defaults to `None`, meaning that the behavior is unchanged)
15+
* New `ReverseColormapTool`: registered by default in the plot widget, like the
16+
`ColormapTool` (add the "Invert colormap" entry in the context menu of the image)
17+
18+
Other changes:
619

720
* Image plot items deserialization:
821
* When an image plot item is deserialized, and needs to be reloaded from a file,

doc/features/tools/overview.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ The `tools` module provides the following tools:
6060
* :py:class:`.tools.ItemListPanelTool`
6161
* :py:class:`.tools.ContrastPanelTool`
6262
* :py:class:`.tools.ColormapTool`
63+
* :py:class:`.tools.ReverseColormapTool`
6364
* :py:class:`.tools.XCSPanelTool`
6465
* :py:class:`.tools.YCSPanelTool`
6566
* :py:class:`.tools.CrossSectionTool`

doc/features/tools/reference.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ Image tools
106106
:members:
107107
.. autoclass:: plotpy.tools.ColormapTool
108108
:members:
109+
.. autoclass:: plotpy.tools.ReverseColormapTool
110+
:members:
109111
.. autoclass:: plotpy.tools.XCSPanelTool
110112
:members:
111113
.. autoclass:: plotpy.tools.YCSPanelTool

plotpy/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
.. _GitHub: https://github.com/PierreRaybaut/plotpy
2121
"""
2222

23-
__version__ = "2.2.1"
23+
__version__ = "2.3.0"
2424
__VERSION__ = tuple([int(number) for number in __version__.split(".")])
2525

2626
# --- Important note: DATAPATH and LOCALEPATH are used by guidata.configtools

plotpy/items/image/base.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,11 +416,15 @@ def set_background_color(self, qcolor: QColor | str) -> None:
416416
else:
417417
self.lut = (a, b, np.uint32(QG.QColor(qcolor).rgb() & 0xFFFFFF), cmap)
418418

419-
def set_color_map(self, name_or_table: str | EditableColormap) -> None:
419+
def set_color_map(
420+
self, name_or_table: str | EditableColormap, invert: bool | None = None
421+
) -> None:
420422
"""Set colormap
421423
422424
Args:
423425
name_or_table: Colormap name or colormap
426+
invert: True to invert colormap, False otherwise (Default value = None,
427+
i.e. do not change the default behavior)
424428
"""
425429
if name_or_table is self.cmap_table:
426430
# This avoids rebuilding the LUT all the time
@@ -429,6 +433,8 @@ def set_color_map(self, name_or_table: str | EditableColormap) -> None:
429433
table = get_cmap(name_or_table)
430434
else:
431435
table = name_or_table
436+
if invert is not None:
437+
table.invert = invert
432438
self.cmap_table = table
433439
self.cmap = table.colorTable(FULLRANGE)
434440
cmap_a = self.lut[3]

plotpy/items/image/filter.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
from plotpy.interfaces import IItemType
4646
from plotpy.items import RawImageItem, XYImageItem
4747
from plotpy.styles import ImageFilterParam, ItemParameters
48+
from plotpy.widgets.colormap.widget import EditableColormap
4849

4950

5051
# ==============================================================================
@@ -188,18 +189,20 @@ def move_with_selection(self, delta_x: float, delta_y: float) -> None:
188189
self.border_rect.move_with_selection(delta_x, delta_y)
189190

190191
def set_color_map(
191-
self, name_or_table: str | qwt.color_map.QwtLinearColorMap
192+
self, name_or_table: str | EditableColormap, invert: bool | None = None
192193
) -> None:
193194
"""Set colormap
194195
195196
Args:
196197
name_or_table: Colormap name or colormap
198+
invert: True to invert colormap, False otherwise (Default value = None,
199+
i.e. do not change the default behavior)
197200
"""
198201
if self.use_source_cmap:
199202
if self.image is not None:
200-
self.image.set_color_map(name_or_table)
203+
self.image.set_color_map(name_or_table, invert)
201204
else:
202-
BaseImageItem.set_color_map(self, name_or_table)
205+
BaseImageItem.set_color_map(self, name_or_table, invert)
203206

204207
def get_color_map(self) -> qwt.color_map.QwtLinearColorMap:
205208
"""Get colormap"""

plotpy/items/image/image_items.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
from qtpy.QtGui import QColor, QPainter
3939

4040
from plotpy.interfaces import IItemType
41+
from plotpy.widgets.colormap.widget import EditableColormap
4142

4243
try:
4344
from plotpy._scaler import INTERP_NEAREST, _scale_rect, _scale_xy
@@ -806,16 +807,14 @@ def set_background_color(self, qcolor: QColor | str) -> None:
806807
self.lut = None
807808

808809
def set_color_map(
809-
self, name_or_table: str | qwt.color_map.QwtLinearColorMap
810+
self, name_or_table: str | EditableColormap, invert: bool | None = None
810811
) -> None:
811812
"""Set colormap
812813
813814
Args:
814815
name_or_table: Colormap name or colormap
815-
816-
.. warning::
817-
818-
This method is not implemented for this item type.
816+
invert: True to invert colormap, False otherwise (Default value = None,
817+
i.e. do not change the default behavior)
819818
"""
820819
self.lut = None
821820

0 commit comments

Comments
 (0)