Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Include scatter plots in Qt figure options editor. #12779

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 10, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
69 changes: 38 additions & 31 deletions lib/matplotlib/backends/qt_editor/figureoptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,39 +137,43 @@ def prepare_data(d, init):
# Is there a curve displayed?
has_curve = bool(curves)

# Get / Images
imagedict = {}
for image in axes.get_images():
label = image.get_label()
if label == '_nolegend_':
# Get ScalarMappables.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor formatting nitpicking. I think we would usually do # get ScalarMappables. Same with the set below.

Copy link
Contributor Author

@anntzer anntzer Nov 9, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I capitalize (nearly) all my comments and include final stops (Matplotlib or not)...

mappabledict = {}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would probably do mappable_* instead of mappable* on compounds for better readability.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's also curvedict/curvedata/etc. for Line2D instances (just above), so if you want to get to change both of them...

for mappable in [*axes.images, *axes.collections]:
label = mappable.get_label()
if label == '_nolegend_' or mappable.get_array() is None:
continue
imagedict[label] = image
imagelabels = sorted(imagedict, key=cmp_key)
images = []
mappabledict[label] = mappable
mappablelabels = sorted(mappabledict, key=cmp_key)
mappables = []
cmaps = [(cmap, name) for name, cmap in sorted(cm.cmap_d.items())]
for label in imagelabels:
image = imagedict[label]
cmap = image.get_cmap()
for label in mappablelabels:
mappable = mappabledict[label]
cmap = mappable.get_cmap()
if cmap not in cm.cmap_d.values():
cmaps = [(cmap, cmap.name)] + cmaps
low, high = image.get_clim()
imagedata = [
cmaps = [(cmap, cmap.name), *cmaps]
low, high = mappable.get_clim()
mappabledata = [
('Label', label),
('Colormap', [cmap.name] + cmaps),
('Min. value', low),
('Max. value', high),
('Interpolation',
[image.get_interpolation()]
+ [(name, name) for name in sorted(mimage.interpolations_names)])]
images.append([imagedata, label, ""])
# Is there an image displayed?
has_image = bool(images)
]
if hasattr(mappable, "get_interpolation"): # Images.
interpolations = [
(name, name) for name in sorted(mimage.interpolations_names)]
mappabledata.append((
'Interpolation',
[mappable.get_interpolation(), *interpolations]))
mappables.append([mappabledata, label, ""])
# Is there a scalarmappable displayed?
has_sm = bool(mappables)

datalist = [(general, "Axes", "")]
if curves:
datalist.append((curves, "Curves", ""))
if images:
datalist.append((images, "Images", ""))
if mappables:
datalist.append((mappables, "Images, etc.", ""))

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

general = data.pop(0)
curves = data.pop(0) if has_curve else []
images = data.pop(0) if has_image else []
mappables = data.pop(0) if has_sm else []
if data:
raise ValueError("Unexpected field")

Expand Down Expand Up @@ -223,14 +227,17 @@ def apply_callback(data):
line.set_markerfacecolor(markerfacecolor)
line.set_markeredgecolor(markeredgecolor)

# Set / Images
for index, image_settings in enumerate(images):
image = imagedict[imagelabels[index]]
label, cmap, low, high, interpolation = image_settings
image.set_label(label)
image.set_cmap(cm.get_cmap(cmap))
image.set_clim(*sorted([low, high]))
image.set_interpolation(interpolation)
# Set ScalarMappables.
for index, mappable_settings in enumerate(mappables):
mappable = mappabledict[mappablelabels[index]]
if len(mappable_settings) == 5:
label, cmap, low, high, interpolation = mappable_settings
mappable.set_interpolation(interpolation)
elif len(mappable_settings) == 4:
label, cmap, low, high = mappable_settings
mappable.set_label(label)
mappable.set_cmap(cm.get_cmap(cmap))
mappable.set_clim(*sorted([low, high]))

# re-generate legend, if checkbox is checked
if generate_legend:
Expand Down
1 change: 1 addition & 0 deletions lib/matplotlib/tests/test_backend_qt.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,7 @@ def test_figureoptions():
fig, ax = plt.subplots()
ax.plot([1, 2])
ax.imshow([[1]])
ax.scatter(range(3), range(3), c=range(3))
with mock.patch(
"matplotlib.backends.qt_editor.formlayout.FormDialog.exec_",
lambda self: None):
Expand Down