Skip to content

Improve Axes selection in Qt figure options. #13375

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
Feb 19, 2019
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
35 changes: 18 additions & 17 deletions lib/matplotlib/backends/backend_qt5.py
Original file line number Diff line number Diff line change
Expand Up @@ -758,30 +758,31 @@ def sizeHint(self):
return size

def edit_parameters(self):
allaxes = self.canvas.figure.get_axes()
if not allaxes:
axes = self.canvas.figure.get_axes()
if not axes:
QtWidgets.QMessageBox.warning(
self.parent, "Error", "There are no axes to edit.")
return
elif len(allaxes) == 1:
axes, = allaxes
elif len(axes) == 1:
ax, = axes
else:
titles = []
for axes in allaxes:
name = (axes.get_title() or
" - ".join(filter(None, [axes.get_xlabel(),
axes.get_ylabel()])) or
"<anonymous {} (id: {:#x})>".format(
type(axes).__name__, id(axes)))
titles.append(name)
titles = [
ax.get_label() or
ax.get_title() or
" - ".join(filter(None, [ax.get_xlabel(), ax.get_ylabel()])) or
f"<anonymous {type(ax).__name__}>"
for ax in axes]
duplicate_titles = [
title for title in titles if titles.count(title) > 1]
for i, ax in enumerate(axes):
if titles[i] in duplicate_titles:
titles[i] += f" (id: {id(ax):#x})" # Deduplicate titles.
item, ok = QtWidgets.QInputDialog.getItem(
self.parent, 'Customize', 'Select axes:', titles, 0, False)
if ok:
axes = allaxes[titles.index(item)]
else:
if not ok:
return

figureoptions.figure_edit(axes, self)
ax = axes[titles.index(item)]
figureoptions.figure_edit(ax, self)

def _update_buttons_checked(self):
# sync button checkstates to match active mode
Expand Down
4 changes: 2 additions & 2 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1437,7 +1437,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
if parent_anchor is not False:
ax.set_anchor(parent_anchor)

cax = fig.add_axes(pbcb)
cax = fig.add_axes(pbcb, label="<colorbar>")

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

fig = parent.get_figure()
cax = fig.add_subplot(gs2[1])
cax = fig.add_subplot(gs2[1], label="<colorbar>")
cax.set_aspect(aspect, anchor=anchor, adjustable='box')
return cax, kw

Expand Down