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

Skip to content

Commit cf0938c

Browse files
committed
TST: added subpanel image tests
1 parent eb78a4e commit cf0938c

File tree

5 files changed

+47
-7
lines changed

5 files changed

+47
-7
lines changed

lib/matplotlib/colorbar.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1479,10 +1479,7 @@ def make_axes(parents, location=None, orientation=None, fraction=0.15,
14791479
if parent_anchor is not False:
14801480
ax.set_anchor(parent_anchor)
14811481

1482-
print('Before', fig._get_draw_artists(fig.canvas.get_renderer()))
14831482
cax = fig.add_axes(pbcb, label="<colorbar>")
1484-
print('Added', cax)
1485-
print(fig._get_draw_artists(fig.canvas.get_renderer()))
14861483
for a in parents:
14871484
# tell the parent it has a colorbar
14881485
a._colorbars += [cax]

lib/matplotlib/figure.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ def __init__(self):
250250
self.figure = self
251251
# list of child gridspecs for this figure
252252
self._gridspecs = []
253-
self._localaxes = _AxesStack() # keep track of axes at this level
253+
self._localaxes = _AxesStack() # keep track of axes at this level
254254
self.artists = []
255255
self.lines = []
256256
self.patches = []
@@ -1146,7 +1146,6 @@ def text(self, x, y, s, fontdict=None, **kwargs):
11461146
self.stale = True
11471147
return text
11481148

1149-
11501149
@docstring.dedent_interpd
11511150
def colorbar(self, mappable, cax=None, ax=None, use_gridspec=True, **kw):
11521151
"""%(colorbar_doc)s"""
@@ -2051,8 +2050,6 @@ def draw(self, renderer):
20512050
self.stale = False
20522051

20532052

2054-
2055-
20562053
class Figure(PanelBase):
20572054
"""
20582055
The top level container for all the plot elements.

lib/matplotlib/tests/test_figure.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -797,3 +797,49 @@ def test_reused_gridspec():
797797

798798
assert gs1 == gs2
799799
assert gs1 == gs3
800+
801+
802+
@image_comparison(['test_subpanel.png'], style='mpl20',
803+
savefig_kwarg={'facecolor': 'teal'},
804+
remove_text=False)
805+
def test_subpanel():
806+
np.random.seed(19680808)
807+
fig = plt.figure(constrained_layout=True)
808+
sub = fig.subpanels(1, 2)
809+
810+
axs = sub[0].subplots(2, 2)
811+
for ax in axs.flat:
812+
pc = ax.pcolormesh(np.random.randn(30, 30), vmin=-2, vmax=2)
813+
sub[0].colorbar(pc, ax=axs)
814+
sub[0].suptitle('Left Side')
815+
816+
axs = sub[1].subplots(1, 3)
817+
for ax in axs.flat:
818+
pc = ax.pcolormesh(np.random.randn(30, 30), vmin=-2, vmax=2)
819+
sub[1].colorbar(pc, ax=axs, location='bottom')
820+
sub[1].suptitle('Right Side')
821+
822+
fig.suptitle('Figure suptitle', fontsize='xx-large')
823+
824+
825+
@image_comparison(['test_subpanel_ss.png'], style='mpl20',
826+
savefig_kwarg={'facecolor': 'teal'},
827+
remove_text=False)
828+
def test_subpanel_ss():
829+
np.random.seed(19680808)
830+
fig = plt.figure(constrained_layout=True)
831+
gs = fig.add_gridspec(1, 2)
832+
833+
sub = fig.add_subpanel(gs[0], facecolor='pink')
834+
835+
axs = sub.subplots(2, 2)
836+
for ax in axs.flat:
837+
pc = ax.pcolormesh(np.random.randn(30, 30), vmin=-2, vmax=2)
838+
sub.colorbar(pc, ax=axs)
839+
sub.suptitle('Left Side')
840+
841+
ax = fig.add_subplot(gs[1])
842+
ax.plot(np.arange(20))
843+
ax.set_title('Axes')
844+
845+
fig.suptitle('Figure suptitle', fontsize='xx-large')

0 commit comments

Comments
 (0)