Skip to content

Commit 86851fd

Browse files
authored
fix quick2D bugs with contour, contourf (#1201)
* Update _quick.py remove unused arg (that breaks Quick2D when contours is enabled) * changelog and tests * issue 1191 - tests pass * Update CHANGELOG.md
1 parent 31bef1c commit 86851fd

4 files changed

Lines changed: 25 additions & 3 deletions

File tree

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/).
55

66
## [Unreleased]
77

8+
### Fixed
9+
- quick2D works with contours on
10+
- quick2D works with `pixelated=False` (i.e. contourf)
11+
812
### Changed
913
- default colorbar is sampled at 4096 points (was 256)
1014

WrightTools/artists/_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def _parse_plot_args(self, *args, **kwargs):
154154
data=data, channel_index=channel_index, dynamic_range=dynamic_range, **kwargs
155155
)
156156
if plot_type == "contourf":
157-
if "levels" not in kwargs.keys():
157+
if "levels" not in kwargs.keys() and "norm" not in kwargs.keys():
158158
kwargs["levels"] = np.linspace(kwargs["vmin"], kwargs["vmax"], 256)
159159
elif plot_type == "contour":
160160
if "levels" not in kwargs.keys():

WrightTools/artists/_quick.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def _quick2D(
302302
fname=None,
303303
):
304304

305-
def determine_contour_levels(local_channel, global_channel, contours, local):
305+
def determine_contour_levels(local_channel, global_channel, local):
306306
# force top and bottom contour to be data range then clip them out
307307
null = local_channel.null
308308
if local_channel.signed:

tests/artists/test_quick2D.py

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,23 @@ def test_perovskite():
4444
handler(True)
4545

4646

47+
def test_contourf_option():
48+
w1 = np.linspace(-2, 2, 51)
49+
w2 = np.linspace(-1, 1, 11)
50+
w3 = np.linspace(1, 3, 5)
51+
signal = np.cos(w1[:, None, None] + w2[None, :, None] + w3[None, None, :])
52+
data = wt.data.Data(name="data")
53+
data.create_channel("signal", values=signal, signed=True)
54+
data.create_variable("w1", values=w1[:, None, None], units="wn", label="1")
55+
data.create_variable("w2", values=w2[None, :, None], units="wn", label="2")
56+
data.create_variable("w3", values=w3[None, None, :], units="wn", label="3")
57+
data.transform("w1", "w2", "w3")
58+
data.moment(2, 0, 0)
59+
# moments bug(?): moment is not signed, even though the data is
60+
handler = wt.artists._quick._quick2D(data, channel=-1, pixelated=False)
61+
handler(True)
62+
63+
4764
def test_4D():
4865
w1 = np.linspace(-3, 3, 3)
4966
w2 = np.linspace(-2, 2, 3)
@@ -62,7 +79,7 @@ def test_4D():
6279
data.create_variable("w3", values=w3[None, None, :, None], units="wn", label="3")
6380
data.create_variable("d1", values=tau[None, None, None, :], units="ps")
6481
data.transform("w1", "w2", "w3", "d1")
65-
wt.artists.quick2D(data, xaxis=0, yaxis=1)
82+
wt.artists.quick2D(data, xaxis=0, yaxis=1, contours=3)
6683

6784

6885
def test_remove_uninvolved_dimensions():
@@ -89,5 +106,6 @@ def test_remove_uninvolved_dimensions():
89106
test_save_arguments()
90107
test_perovskite()
91108
test_4D()
109+
test_contourf_option()
92110
test_remove_uninvolved_dimensions()
93111
plt.show()

0 commit comments

Comments
 (0)