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

Skip to content

Make colorbar compatible accepting a list of axes created via gridspec #8755

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

Closed
wants to merge 27 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
1b0ac37
Clarify how a FancyArrowPatch behaves
dstansby Jun 2, 2017
070a578
Clarify in display units
dstansby Jun 7, 2017
089818b
Allow divmod to be overridden by numpy
dstansby Jun 9, 2017
b87778e
Various cleanups to backends code.
anntzer Jun 3, 2017
40fa293
Update FreeType version in test_tightlayout4.
QuLogic Jun 2, 2017
c0ecc7d
Add a unique number to any renderer hash keys.
QuLogic Jun 3, 2017
df672df
Update tests that are marked flaky.
QuLogic Jun 3, 2017
9bf168f
Use itertools.count for renderer unique ID.
QuLogic Jun 4, 2017
454e9d6
Simplify cla sharex/sharey code; alternative to #8710
efiring Jun 4, 2017
edfdc53
MNT: colorbar accept numpy array input (#8739)
jklymak Jun 12, 2017
2284e98
Changed normalization in _spectral_helper() to obtain conistent scali…
DietBru May 6, 2017
234089d
Added note to api_changes
DietBru Jun 11, 2017
a62d3e3
Fix contour colour level determination
dstansby Jun 9, 2017
03c00d7
Correct contour level test
dstansby Jun 9, 2017
65f3906
sort input files
bmwiedemann Jun 12, 2017
62aa006
First pass; seems to work. More testing needed
jklymak Jun 13, 2017
fb3f419
First pass; seems to work. More testing needed
jklymak Jun 13, 2017
89857c7
First pass; seems to work. More testing needed
jklymak Jun 13, 2017
c68a411
First pass; seems to work. More testing needed
jklymak Jun 13, 2017
031d356
First change
jklymak Jun 13, 2017
1c5a14e
Aded comments and cleaned up
jklymak Jun 13, 2017
12737f5
Aded comments and cleaned up
jklymak Jun 13, 2017
600253e
Colormap that handles gridspec
jklymak Jun 13, 2017
fd388aa
Colormap that handles gridspec
jklymak Jun 13, 2017
262fa33
Colormap that handles gridspec
jklymak Jun 13, 2017
37998b4
Fixed subplotspec geometry having None
jklymak Jun 13, 2017
d9b49b5
Fixed subplotspec geometry having None, PEP8 errors
jklymak Jun 13, 2017
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
Prev Previous commit
Next Next commit
First pass; seems to work. More testing needed
  • Loading branch information
jklymak committed Jun 13, 2017
commit fb3f41963f40b954236793915aa7a0e36cb77b9f
72 changes: 19 additions & 53 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
import matplotlib.patches as mpatches
import matplotlib.path as mpath
import matplotlib.ticker as ticker
import matplotlib.transforms as mtransforms
import matplotlib.transforms as mtrans

from matplotlib import docstring

Expand Down Expand Up @@ -317,7 +317,7 @@ def __init__(self, ax, cmap=None,
linthresh=self.norm.linthresh)
else:
self.formatter = ticker.ScalarFormatter()
elif isinstance(format, six.string_types):
elif cbook.is_string_like(format):
self.formatter = ticker.FormatStrFormatter(format)
else:
self.formatter = format # Assume it is a Formatter
Expand All @@ -344,7 +344,6 @@ def draw_all(self):
Calculate any free parameters based on the current cmap and norm,
and do all the drawing.
'''

self._process_values()
self._find_range()
X, Y = self._mesh()
Expand Down Expand Up @@ -400,10 +399,6 @@ def set_ticks(self, ticks, update_ticks=True):
self.update_ticks()
self.stale = True

def get_ticks(self, minor=False):
"""Return the x ticks as a list of locations"""
return self._tick_data_values

def set_ticklabels(self, ticklabels, update_ticks=True):
"""
set tick labels. Tick labels are updated immediately unless
Expand Down Expand Up @@ -616,7 +611,6 @@ def _ticker(self):
else:
eps = (intv[1] - intv[0]) * 1e-10
b = b[(b <= intv[1] + eps) & (b >= intv[0] - eps)]
self._tick_data_values = b
ticks = self._locate(b)
formatter.set_locs(b)
ticklabels = [formatter(t, i) for i, t in enumerate(b)]
Expand Down Expand Up @@ -687,10 +681,9 @@ def _process_values(self, b=None):
self.norm.vmin = 0
self.norm.vmax = 1

self.norm.vmin, self.norm.vmax = mtransforms.nonsingular(
self.norm.vmin,
self.norm.vmax,
expander=0.1)
self.norm.vmin, self.norm.vmax = mtrans.nonsingular(self.norm.vmin,
self.norm.vmax,
expander=0.1)

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

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

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

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

# take a bounding box around all of the given axes
parents_bbox = mtransforms.Bbox.union(
[ax.get_position(original=True).frozen() for ax in parents])
parents_bbox = mtrans.Bbox.union([ax.get_position(original=True).frozen()
for ax in parents])

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

# define a transform which takes us from old axes coordinates to
# new axes coordinates
shrinking_trans = mtransforms.BboxTransform(parents_bbox, pb1)
shrinking_trans = mtrans.BboxTransform(parents_bbox, pb1)

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


@docstring.Substitution(make_axes_kw_doc)
def make_axes_gridspec(parents, **kw):
def make_axes_gridspec(parent, **kw):
'''
Resize and reposition a parent axes, and return a child axes
suitable for a colorbar. This function is similar to
Expand Down Expand Up @@ -1213,35 +1204,13 @@ def make_axes_gridspec(parents, **kw):
pad_s = (1. - shrink) * 0.5
wh_ratios = [pad_s, shrink, pad_s]

# make parents a 1-d ndarray if its not already...
parents = np.atleast_1d(parents).ravel()
# get the appropriate subplot spec. Loop through the parents.
gs0 = parents[0].get_subplotspec().get_gridspec()
minind = 10000
maxind = -10000
for parent in parents:
gs = parent.get_subplotspec().get_gridspec()
if gs == gs0:
ss = parent.get_subplotspec().get_geometry()
if ss[2]<minind:
minind = ss[2]
if ss[3]>maxind:
maxind = ss[3]
else:
pass
print(minind)
print(maxind)
subspec = gridspec.SubplotSpec(gs0,minind,maxind)
print(subspec)
print(subspec.get_geometry())

gs_from_subplotspec = gridspec.GridSpecFromSubplotSpec
if orientation == 'vertical':
pad = kw.pop('pad', 0.05)
wh_space = 2 * pad / (1 - pad)

gs = gs_from_subplotspec(1, 2,
subplot_spec=subspec,
subplot_spec=parent.get_subplotspec(),
wspace=wh_space,
width_ratios=[x1 - pad, fraction]
)
Expand All @@ -1251,8 +1220,6 @@ def make_axes_gridspec(parents, **kw):
hspace=0.,
height_ratios=wh_ratios,
)
print(gs)
print(gs2)

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

gs = gs_from_subplotspec(2, 1,
subplot_spec=subspec,
subplot_spec=parent.get_subplotspec(),
hspace=wh_space,
height_ratios=[x1 - pad, fraction]
)
Expand All @@ -1276,13 +1243,12 @@ def make_axes_gridspec(parents, **kw):
anchor = (0.5, 1.0)
panchor = (0.5, 0.0)

for parent in parents:
parent.set_subplotspec(gs[0])
parent.update_params()
parent.set_position(parent.figbox)
parent.set_anchor(panchor)
parent.set_subplotspec(gs[0])
parent.update_params()
parent.set_position(parent.figbox)
parent.set_anchor(panchor)

fig = parents[0].get_figure()
fig = parent.get_figure()
cax = fig.add_subplot(gs2[1])
cax.set_aspect(aspect, anchor=anchor, adjustable='box')
return cax, kw
Expand Down
Loading