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 812d826

Browse filesBrowse files
committed
Include scatter plots in Qt figure options editor.
Essentially all the image-handling code can be reused; the only difference is that collections don't have an `interpolation` field so we need to check for that. The rest of the PR is just replacing "image" by "sm" ("ScalarMappable") throughout...
1 parent 4dbbd22 commit 812d826
Copy full SHA for 812d826

File tree

Expand file treeCollapse file tree

2 files changed

+39
-31
lines changed
Filter options
Expand file treeCollapse file tree

2 files changed

+39
-31
lines changed

‎lib/matplotlib/backends/qt_editor/figureoptions.py

Copy file name to clipboardExpand all lines: lib/matplotlib/backends/qt_editor/figureoptions.py
+38-31Lines changed: 38 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -137,39 +137,43 @@ def prepare_data(d, init):
137137
# Is there a curve displayed?
138138
has_curve = bool(curves)
139139

140-
# Get / Images
141-
imagedict = {}
142-
for image in axes.get_images():
143-
label = image.get_label()
144-
if label == '_nolegend_':
140+
# Get ScalarMappables.
141+
mappabledict = {}
142+
for mappable in [*axes.images, *axes.collections]:
143+
label = mappable.get_label()
144+
if label == '_nolegend_' or mappable.get_array() is None:
145145
continue
146-
imagedict[label] = image
147-
imagelabels = sorted(imagedict, key=cmp_key)
148-
images = []
146+
mappabledict[label] = mappable
147+
mappablelabels = sorted(mappabledict, key=cmp_key)
148+
mappables = []
149149
cmaps = [(cmap, name) for name, cmap in sorted(cm.cmap_d.items())]
150-
for label in imagelabels:
151-
image = imagedict[label]
152-
cmap = image.get_cmap()
150+
for label in mappablelabels:
151+
mappable = mappabledict[label]
152+
cmap = mappable.get_cmap()
153153
if cmap not in cm.cmap_d.values():
154-
cmaps = [(cmap, cmap.name)] + cmaps
155-
low, high = image.get_clim()
156-
imagedata = [
154+
cmaps = [(cmap, cmap.name), *cmaps]
155+
low, high = mappable.get_clim()
156+
mappabledata = [
157157
('Label', label),
158158
('Colormap', [cmap.name] + cmaps),
159159
('Min. value', low),
160160
('Max. value', high),
161-
('Interpolation',
162-
[image.get_interpolation()]
163-
+ [(name, name) for name in sorted(mimage.interpolations_names)])]
164-
images.append([imagedata, label, ""])
165-
# Is there an image displayed?
166-
has_image = bool(images)
161+
]
162+
if hasattr(mappable, "get_interpolation"): # Images.
163+
mappabledata.append((
164+
'Interpolation',
165+
[mappable.get_interpolation(),
166+
*((name, name)
167+
for name in sorted(mimage.interpolations_names))]))
168+
mappables.append([mappabledata, label, ""])
169+
# Is there a scalarmappable displayed?
170+
has_sm = bool(mappables)
167171

168172
datalist = [(general, "Axes", "")]
169173
if curves:
170174
datalist.append((curves, "Curves", ""))
171-
if images:
172-
datalist.append((images, "Images", ""))
175+
if mappables:
176+
datalist.append((mappables, "Images, etc.", ""))
173177

174178
def apply_callback(data):
175179
"""This function will be called to apply changes"""
@@ -178,7 +182,7 @@ def apply_callback(data):
178182

179183
general = data.pop(0)
180184
curves = data.pop(0) if has_curve else []
181-
images = data.pop(0) if has_image else []
185+
mappables = data.pop(0) if has_sm else []
182186
if data:
183187
raise ValueError("Unexpected field")
184188

@@ -223,14 +227,17 @@ def apply_callback(data):
223227
line.set_markerfacecolor(markerfacecolor)
224228
line.set_markeredgecolor(markeredgecolor)
225229

226-
# Set / Images
227-
for index, image_settings in enumerate(images):
228-
image = imagedict[imagelabels[index]]
229-
label, cmap, low, high, interpolation = image_settings
230-
image.set_label(label)
231-
image.set_cmap(cm.get_cmap(cmap))
232-
image.set_clim(*sorted([low, high]))
233-
image.set_interpolation(interpolation)
230+
# Set ScalarMappables.
231+
for index, mappable_settings in enumerate(mappables):
232+
mappable = mappabledict[mappablelabels[index]]
233+
if len(mappable_settings) == 5:
234+
label, cmap, low, high, interpolation = mappable_settings
235+
mappable.set_interpolation(interpolation)
236+
elif len(mappable_settings) == 4:
237+
label, cmap, low, high = mappable_settings
238+
mappable.set_label(label)
239+
mappable.set_cmap(cm.get_cmap(cmap))
240+
mappable.set_clim(*sorted([low, high]))
234241

235242
# re-generate legend, if checkbox is checked
236243
if generate_legend:

‎lib/matplotlib/tests/test_backend_qt.py

Copy file name to clipboardExpand all lines: lib/matplotlib/tests/test_backend_qt.py
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,7 @@ def test_figureoptions():
250250
fig, ax = plt.subplots()
251251
ax.plot([1, 2])
252252
ax.imshow([[1]])
253+
ax.scatter(range(3), range(3), c=range(3))
253254
with mock.patch(
254255
"matplotlib.backends.qt_editor.formlayout.FormDialog.exec_",
255256
lambda self: None):

0 commit comments

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