10000 First pass; seems to work. More testing needed · matplotlib/matplotlib@fb3f419 · GitHub
[go: up one dir, main page]

Skip to content

Commit fb3f419

Browse files
committed
First pass; seems to work. More testing needed
1 parent 62aa006 commit fb3f419

File tree

2 files changed

+162
-417
lines changed

2 files changed

+162
-417
lines changed

lib/matplotlib/colorbar.py

Lines changed: 19 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
import matplotlib.patches as mpatches
4040
import matplotlib.path as mpath
4141
import matplotlib.ticker as ticker
42-
import matplotlib.transforms as mtransforms
42+
import matplotlib.transforms as mtrans
4343

4444
from matplotlib import docstring
4545

@@ -317,7 +317,7 @@ def __init__(self, ax, cmap=None,
317317
linthresh=self.norm.linthresh)
318318
else:
319319
self.formatter = ticker.ScalarFormatter()
320-
elif isinstance(format, six.string_types):
320+
elif cbook.is_string_like(format):
321321
self.formatter = ticker.FormatStrFormatter(format)
322322
else:
323323
self.formatter = format # Assume it is a Formatter
@@ -344,7 +344,6 @@ def draw_all(self):
344344
Calculate any free parameters based on the current cmap and norm,
345345
and do all the drawing.
346346
'''
347-
348347
self._process_values()
349348
self._find_range()
350349
X, Y = self._mesh()
@@ -400,10 +399,6 @@ def set_ticks(self, ticks, update_ticks=True):
400399
self.update_ticks()
401400
self.stale = True
402401

403-
def get_ticks(self, minor=False):
404-
"""Return the x ticks as a list of locations"""
405-
return self._tick_data_values
406-
407402
def set_ticklabels(self, ticklabels, update_ticks=True):
408403
"""
409404
set tick labels. Tick labels are updated immediately unless
@@ -616,7 +611,6 @@ def _ticker(self):
616611
else:
617612
eps = (intv[1] - intv[0]) * 1e-10
618613
b = b[(b <= intv[1] + eps) & (b >= intv[0] - eps)]
619-
self._tick_data_values = b
620614
ticks = self._locate(b)
621615
formatter.set_locs(b)
622616
ticklabels = [formatter(t, i) for i, t in enumerate(b)]
@@ -687,10 +681,9 @@ def _process_values(self, b=None):
687681
self.norm.vmin = 0
688682
self.norm.vmax = 1
689683

690-
self.norm.vmin, self.norm.vmax = mtransforms.nonsingular(
691-
self.norm.vmin,
692-
self.norm.vmax,
693-
expander=0.1)
684+
self.norm.vmin, self.norm.vmax = mtrans.nonsingular(self.norm.vmin,
685+
self.norm.vmax,
686+
expander=0.1)
694687

695688
b = self.norm.inverse(self._uniform_y(self.cmap.N + 1))
696689

@@ -1117,19 +1110,17 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
11171110
parent_anchor = kw.pop('panchor', loc_settings['panchor'])
11181111
pad = kw.pop('pad', loc_settings['pad'])
11191112

1120-
# turn parents into a list if it is not already. We do this w/ np
1121-
# because `plt.subplots` can return an ndarray and is natural to
1122-
# pass to `colorbar`.
1123-
parents = np.atleast_1d(parents).ravel()
1113+
# turn parents into a list if it is not already
1114+
parents = np.atleast_1d(parents).ravel().tolist()
11241115

11251116
fig = parents[0].get_figure()
11261117
if not all(fig is ax.get_figure() for ax in parents):
11271118
raise ValueError('Unable to create a colorbar axes as not all '
11281119
'parents share the same figure.')
11291120

11301121
# take a bounding box around all of the given axes
1131-
parents_bbox = mtransforms.Bbox.union(
1132-
[ax.get_position(original=True).frozen() for ax in parents])
1122+
parents_bbox = mtrans.Bbox.union([ax.get_position(original=True).frozen()
1123+
for ax in parents])
11331124

11341125
pb = parents_bbox
11351126
if location in ('left', 'right'):
@@ -1150,12 +1141,12 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
11501141

11511142
# define a transform which takes us from old axes coordinates to
11521143
# new axes coordinates
1153-
shrinking_trans = mtransforms.BboxTransform(parents_bbox, pb1)
1144+
shrinking_trans = mtrans.BboxTransform(parents_bbox, pb1)
11541145

11551146
# transform each of the axes in parents using the new transform
11561147
for ax in parents:
11571148
new_posn = shrinking_trans.transform(ax.get_position())
1158-
new_posn = mtransforms.Bbox(new_posn)
1149+
new_posn = mtrans.Bbox(new_posn)
11591150
ax.set_position(new_posn)
11601151
if parent_anchor is not False:
11611152
ax.set_anchor(parent_anchor)
@@ -1166,7 +1157,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
11661157

11671158

11681159
@docstring.Substitution(make_axes_kw_doc)
1169-
def make_axes_gridspec(parents, **kw):
1160+
def make_axes_gridspec(parent, **kw):
11701161
'''
11711162
Resize and reposition a parent axes, and return a child axes
11721163
suitable for a colorbar. This function is similar to
@@ -1213,35 +1204,13 @@ def make_axes_gridspec(parents, **kw):
12131204
pad_s = (1. - shrink) * 0.5
12141205
wh_ratios = [pad_s, shrink, pad_s]
12151206

1216-
# make parents a 1-d ndarray if its not already...
1217-
parents = np.atleast_1d(parents).ravel()
1218-
# get the appropriate subplot spec. Loop through the parents.
1219-
gs0 = parents[0].get_subplotspec().get_gridspec()
1220-
minind = 10000
1221-
maxind = -10000
1222-
for parent in parents:
1223-
gs = parent.get_subplotspec().get_gridspec()
1224-
if gs == gs0:
1225-
ss = parent.get_subplotspec().get_geometry()
1226-
if ss[2]<minind:
1227-
minind = ss[2]
1228-
if ss[3]>maxind:
1229-
maxind = ss[3]
1230-
else:
1231-
pass
1232-
print(minind)
1233-
print(maxind)
1234-
subspec = gridspec.SubplotSpec(gs0,minind,maxind)
1235-
print(subspec)
1236-
print(subspec.get_geometry())
1237-
12381207
gs_from_subplotspec = gridspec.GridSpecFromSubplotSpec
12391208
if orientation == 'vertical':
12401209
pad = kw.pop('pad', 0.05)
12411210
wh_space = 2 * pad / (1 - pad)
12421211

12431212
gs = gs_from_subplotspec(1, 2,
1244-
subplot_spec=subspec,
1213+
subplot_spec=parent.get_subplotspec(),
12451214
wspace=wh_space,
12461215
width_ratios=[x1 - pad, fraction]
12471216
)
@@ -1251,8 +1220,6 @@ def make_axes_gridspec(parents, **kw):
12511220
hspace=0.,
12521221
height_ratios=wh_ratios,
12531222
)
1254-
print(gs)
1255-
print(gs2)
12561223

12571224
anchor = (0.0, 0.5)
12581225
panchor = (1.0, 0.5)
@@ -1261,7 +1228,7 @@ def make_axes_gridspec(parents, **kw):
12611228
wh_space = 2 * pad / (1 - pad)
12621229

12631230
gs = gs_from_subplotspec(2, 1,
1264-
subplot_spec=subspec,
1231+
subplot_spec=parent.get_subplotspec(),
12651232
hspace=wh_space,
12661233
height_ratios=[x1 - pad, fraction]
12671234
)
@@ -1276,13 +1243,12 @@ def make_axes_gridspec(parents, **kw):
12761243
anchor = (0.5, 1.0)
12771244
panchor = (0.5, 0.0)
12781245

1279-
for parent in parents:
1280-
parent.set_subplotspec(gs[0])
1281-
parent.update_params()
1282-
parent.set_position(parent.figbox)
1283-
parent.set_anchor(panchor)
1246+
parent.set_subplotspec(gs[0])
1247+
parent.update_params()
1248+
parent.set_position(parent.figbox)
1249+
parent.set_anchor(panchor)
12841250

1285-
fig = parents[0].get_figure()
1251+
fig = parent.get_figure()
12861252
cax = fig.add_subplot(gs2[1])
12871253
cax.set_aspect(aspect, anchor=anchor, adjustable='box')
12881254
return cax, kw

0 commit comments

Comments
 (0)
0