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

Skip to content

Commit e22f6e8

Browse files
authored
Merge pull request #13375 from anntzer/figureoptions
Improve Axes selection in Qt figure options.
2 parents 7a7a40f + 1cfdb74 commit e22f6e8

File tree

2 files changed

+20
-19
lines changed

2 files changed

+20
-19
lines changed

lib/matplotlib/backends/backend_qt5.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -746,30 +746,31 @@ def sizeHint(self):
746746
return size
747747

748748
def edit_parameters(self):
749-
allaxes = self.canvas.figure.get_axes()
750-
if not allaxes:
749+
axes = self.canvas.figure.get_axes()
750+
if not axes:
751751
QtWidgets.QMessageBox.warning(
752752
self.parent, "Error", "There are no axes to edit.")
753753
return
754-
elif len(allaxes) == 1:
755-
axes, = allaxes
754+
elif len(axes) == 1:
755+
ax, = axes
756756
else:
757-
titles = []
758-
for axes in allaxes:
759-
name = (axes.get_title() or
760-
" - ".join(filter(None, [axes.get_xlabel(),
761-
axes.get_ylabel()])) or
762-
"<anonymous {} (id: {:#x})>".format(
763-
type(axes).__name__, id(axes)))
764-
titles.append(name)
757+
titles = [
758+
ax.get_label() or
759+
ax.get_title() or
760+
" - ".join(filter(None, [ax.get_xlabel(), ax.get_ylabel()])) or
761+
f"<anonymous {type(ax).__name__}>"
762+
for ax in axes]
763+
duplicate_titles = [
764+
title for title in titles if titles.count(title) > 1]
765+
for i, ax in enumerate(axes):
766+
if titles[i] in duplicate_titles:
767+
titles[i] += f" (id: {id(ax):#x})" # Deduplicate titles.
765768
item, ok = QtWidgets.QInputDialog.getItem(
766769
self.parent, 'Customize', 'Select axes:', titles, 0, False)
767-
if ok:
768-
axes = allaxes[titles.index(item)]
769-
else:
770+
if not ok:
770771
return
771-
772-
figureoptions.figure_edit(axes, self)
772+
ax = axes[titles.index(item)]
773+
figureoptions.figure_edit(ax, self)
773774

774775
def _update_buttons_checked(self):
775776
# sync button checkstates to match active mode

lib/matplotlib/colorbar.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
14341434
if parent_anchor is not False:
14351435
ax.set_anchor(parent_anchor)
14361436

1437-
cax = fig.add_axes(pbcb)
1437+
cax = fig.add_axes(pbcb, label="<colorbar>")
14381438

14391439
# OK, now make a layoutbox for the cb axis. Later, we will use this
14401440
# to make the colorbar fit nicely.
@@ -1548,7 +1548,7 @@ def make_axes_gridspec(parent, *, fraction=0.15, shrink=1.0, aspect=20, **kw):
15481548
parent.set_anchor(panchor)
15491549

15501550
fig = parent.get_figure()
1551-
cax = fig.add_subplot(gs2[1])
1551+
cax = fig.add_subplot(gs2[1], label="<colorbar>")
15521552
cax.set_aspect(aspect, anchor=anchor, adjustable='box')
15531553
return cax, kw
15541554

0 commit comments

Comments
 (0)