8000 Make colorbar compatible accepting a list of axes created via gridspec by jklymak · Pull Request #8755 · matplotlib/matplotlib · GitHub
[go: up one dir, main page]

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
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
Aded comments and cleaned up
  • Loading branch information
jklymak committed Jun 13, 2017
commit 1c5a14edcc47f5366bf2443485170d0195a6b79f
45 changes: 20 additions & 25 deletions lib/matplotlib/colorbar.py
Original file line number Diff line number Diff line change
Expand Up @@ -1179,7 +1179,7 @@ def make_axes_gridspec(parents, **kw):
'''
Resize and reposition a parent axes, and return a child axes
suitable for a colorbar. This function is similar to
make_axes. Prmary differences are
make_axes. Primary differences are

* *make_axes_gridspec* only handles the *orientation* keyword
and cannot handle the "location" keyword.
Expand Down Expand Up @@ -1224,10 +1224,11 @@ def make_axes_gridspec(parents, **kw):

# 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.
# For the subplotspec that these axes belong to, loop through and get
# the maximum and minimum index into the subplotspec. The result is the
# size the new gridspec that we will create must be.
gsp0 = parents[0].get_subplotspec().get_gridspec()
minind = 10000
maxind = -10000
minind = 10000;maxind = -10000
for parent in parents:
gsp = parent.get_subplotspec().get_gridspec()
if gsp == gsp0:
Expand All @@ -1238,47 +1239,37 @@ def make_axes_gridspec(parents, **kw):
if ss[3]>maxind:
maxind = ss[3]
else:
pass
# get from maxind and minind to nrows and ncols..
raise NotImplementedError('List of axes passed to colorbar must be from the same gridspec or call to plt.subplots')
# map the extent of the gridspec from indices to rows and columns.
# We need this below to assign the parents into the new gridspec.
ncols0 = gsp0.get_geometry()[1]
print(ncols0)
print(maxind)

minrow,mincol=index2rowcolunm(minind,ncols0)
maxrow,maxcol=index2rowcolunm(maxind,ncols0)
print('mnind %d maxind %d'%(minind,maxind))
print('mncol %d maxcol %d'%(mincol,maxcol))
print('mnrow %d maxrow %d'%(minrow,maxrow))
nrows = maxrow-minrow+1
ncols = maxcol-mincol+1

print('nrows %d ncols %d'%(nrows,ncols))
print(minind)
print(maxind)
# this is subplot spec the region that we need to resize and add
# a colorbar to.
subspec = gridspec.SubplotSpec(gsp0,minind,maxind)
print('GSP0')
print(gsp0.get_geometry())
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)

# split the subplotspec containing parents into two, with one only
# `fraction` wide for the colorbar, and the other with some padding.
gs = gs_from_subplotspec(1, 2,
subplot_spec=subspec,
wspace=wh_space,
width_ratios=[x1 - pad, fraction]
)

# center the colorbar vertically.
gs2 = gs_from_subplotspec(3, 1,
subplot_spec=gs[1],
hspace=0.,
height_ratios=wh_ratios,
)
print(gs)
print(gs2)

anchor = (0.0, 0.5)
panchor = (1.0, 0.5)
Expand Down Expand Up @@ -1310,18 +1301,22 @@ def make_axes_gridspec(parents, **kw):
for parent in parents:
geo=parent.get_subplotspec().get_geometry()
ncol0 = geo[1]
print("Parent Geo:")
print(geo)

# remap the old min gridspec index (geo[2]) into a new
# index.
oldrow,oldcol = index2rowcolunm(geo[2],ncol0)
newrow = oldrow-minrow+1
newcol = oldcol-mincol+1
newminind = rowcolunm2index(newrow,newcol,ncols)

# remap the old max gridspec index (geo[3]) into a new
# index.
oldrow,oldcol = index2rowcolunm(geo[3],ncol0)
newrow = oldrow-minrow+1
newcol = oldcol-mincol+1
newmaxind = rowcolunm2index(newrow,newcol,ncols)
print('newminind %d newmaxind %d'%(newminind,newmaxind))

# change the subplotspec for this parent.
parent.set_subplotspec(gridspec.SubplotSpec(gsnew,newminind,newmaxind))
parent.update_params()
parent.set_position(parent.figbox)
Expand Down
0