Movatterモバイル変換


[0]ホーム

URL:


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

Sign up
Appearance settings

Commitfb768c7

Browse files
committed
Deal with axes_grid differences
1 parentf084fcb commitfb768c7

File tree

2 files changed

+20
-25
lines changed

2 files changed

+20
-25
lines changed

‎lib/matplotlib/colorbar.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -239,15 +239,19 @@ def __init__(self, parent, userax=True):
239239
parent._axes.add_child_axes(outer_ax)
240240
outer_ax._axes.child_axes.remove(parent)
241241
else:
242-
parent.remove()
242+
try:
243+
parent.remove()
244+
exceptValueError:
245+
pass# Already removed
243246
else:
244247
outer_ax=parent
245248

246-
# swap axes in the stack:
247-
fig._localaxes.remove(outer_ax)
248-
fig._axstack.remove(outer_ax)
249-
fig._localaxes.add(self)
250-
fig._axstack.add(self)
249+
# swap axes in the stack if its in there:
250+
ifouter_axinfig._localaxes:
251+
fig._localaxes.remove(outer_ax)
252+
fig._axstack.remove(outer_ax)
253+
fig._localaxes.add(self)
254+
fig._axstack.add(self)
251255
inner_ax=outer_ax.inset_axes([0,0,1,1])
252256
self.__dict__.update(inner_ax.__dict__)
253257

@@ -261,8 +265,8 @@ def __init__(self, parent, userax=True):
261265
self.outer_ax.set_xticks=self.inner_ax.set_xticks
262266
self.outer_ax.set_yticks=self.inner_ax.set_yticks
263267
forattrin ["get_position","set_aspect",
264-
"_remove_method","_set_position",
265-
"set_position"]:
268+
"_remove_method","_set_position",
269+
"set_position","cla","draw"]:
266270
setattr(self,attr,getattr(self.outer_ax,attr))
267271
self._colorbar_info=None# used for mpl-created axes
268272
ifhasattr(self.outer_ax,"get_subplotspec"):
@@ -272,7 +276,11 @@ def __init__(self, parent, userax=True):
272276
ifuserax:
273277
self._colorbar_info='user'
274278
# point the parent's methods all at this axes...
279+
origdict=parent.__dict__
275280
parent.__dict__=self.__dict__
281+
forkeyinorigdict.keys():
282+
ifkeynotinparent.__dict__:
283+
parent.__dict__[key]=origdict[key]
276284

277285
def_set_inner_bounds(self,bounds):
278286
"""
@@ -281,9 +289,6 @@ def _set_inner_bounds(self, bounds):
281289
self.inner_ax._axes_locator=_TransformedBoundsLocator(
282290
bounds,self.outer_ax.transAxes)
283291

284-
defdraw(self,renderer):
285-
self.outer_ax.draw(renderer)
286-
287292

288293
class_ColorbarSpine(mspines.Spine):
289294
def__init__(self,axes):

‎lib/mpl_toolkits/axes_grid1/axes_grid.py

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
importnumpyasnp
55

6-
importmatplotlibasmpl
76
frommatplotlibimport_api
87
frommatplotlib.gridspecimportSubplotSpec
98

@@ -29,28 +28,19 @@ def colorbar(self, mappable, *, ticks=None, **kwargs):
2928
orientation= (
3029
"horizontal"ifself.orientationin ["top","bottom"]else
3130
"vertical")
32-
kwargs['userax']=False
33-
cb=mpl.colorbar.Colorbar(
34-
self,mappable,orientation=orientation,ticks=ticks,**kwargs)
35-
self._config_axes()
31+
cb=self.figure.colorbar(mappable,cax=self,orientation=orientation,
32+
ticks=ticks,**kwargs)
3633
returncb
3734

38-
def_config_axes(self):
39-
"""Make an axes patch and outline."""
40-
ax=self
41-
ax.set_navigate(False)
42-
ax.axis[:].toggle(all=False)
43-
b=self._default_label_on
44-
ax.axis[self.orientation].toggle(all=b)
45-
4635
deftoggle_label(self,b):
4736
self._default_label_on=b
4837
axis=self.axis[self.orientation]
4938
axis.toggle(ticklabels=b,label=b)
5039

5140
defcla(self):
41+
orientation=self.orientation
5242
super().cla()
53-
self._config_axes()
43+
self.orientation=orientation
5444

5545

5646
classCbarAxes(CbarAxesBase,Axes):

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp