-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathtest_subplots.py
More file actions
168 lines (147 loc) · 5.23 KB
/
Copy pathtest_subplots.py
File metadata and controls
168 lines (147 loc) · 5.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
#!/usr/bin/env python3
"""
Test subplot layout.
"""
import numpy as np
import proplot as pplt
@pplt.tests.image_compare
def test_align_labels():
"""
Test spanning and aligned labels.
"""
fig, axs = pplt.subplots(
[[2, 1, 4], [2, 3, 5]], refnum=2, refwidth=1.5, align=1, span=0
)
fig.format(xlabel='xlabel', ylabel='ylabel', abc='A.', abcloc='ul')
axs[0].format(ylim=(10000, 20000))
axs[-1].panel_axes('bottom', share=False)
@pplt.tests.image_compare
def test_share_all_basic():
"""
Test sharing level all.
"""
# Simple example
N = 10
fig, axs = pplt.subplots(nrows=1, ncols=2, refwidth=1.5, share='all')
axs[0].plot(np.arange(N) * 1e2, np.arange(N) * 1e4)
# Complex example
fig, axs = pplt.subplots(nrows=2, ncols=2, refwidth=1.5, share='all')
axs[0].panel('b')
pax = axs[0].panel('r')
pax.format(ylabel='label')
axs[0].plot(np.arange(N) * 1e2, np.arange(N) * 1e4)
@pplt.tests.image_compare
def test_span_labels():
"""
Rigorous tests of spanning and aligned labels feature.
"""
fig, axs = pplt.subplots([[1, 2, 4], [1, 3, 5]], refwidth=1.5, share=0, span=1)
fig.format(xlabel='xlabel', ylabel='ylabel', abc='A.', abcloc='ul')
axs[1].format() # xlabel='xlabel')
axs[2].format()
@pplt.tests.image_compare
def test_title_deflection():
"""
Test the deflection of titles above and below panels.
"""
fig, ax = pplt.subplots()
# ax.format(abc='A.', title='Title', titleloc='left', titlepad=30)
tax = ax.panel_axes('top')
ax.format(titleabove=False) # redirects to bottom
ax.format(abc='A.', title='Title', titleloc='left', titlepad=50)
ax.format(xlabel='xlabel', ylabel='ylabel', ylabelpad=50)
tax.format(title='Fear Me', title_kw={'size': 'x-large'})
tax.format(ultitle='Inner', titlebbox=True, title_kw={'size': 'med-large'})
@pplt.tests.image_compare
def test_complex_ticks():
"""
Normally title offset with these different tick arrangements is tricky
but `_update_title_position` accounts for edge cases.
"""
fig, axs = pplt.subplots(ncols=2)
axs[0].format(
xtickloc='both',
xticklabelloc='top',
xlabelloc='top',
title='title',
xlabel='xlabel',
suptitle='Test',
)
axs[1].format(
xtickloc='both',
xticklabelloc='top',
# xlabelloc='top',
xlabel='xlabel',
title='title',
suptitle='Test',
)
@pplt.tests.image_compare
def test_both_ticklabels():
"""
Test both tick labels.
"""
fig, ax = pplt.subplots() # when both, have weird bug
ax.format(xticklabelloc='both', title='title', suptitle='Test')
fig, ax = pplt.subplots() # when *just top*, bug disappears
ax.format(xtickloc='top', xticklabelloc='top', title='title', suptitle='Test')
fig, ax = pplt.subplots() # not sure here
ax.format(xtickloc='both', xticklabelloc='neither', suptitle='Test')
fig, ax = pplt.subplots() # doesn't seem to change the title offset though
ax.format(xtickloc='top', xticklabelloc='neither', suptitle='Test')
@pplt.tests.image_compare
def test_gridspec_copies():
"""
Test whether gridspec copies work.
"""
fig1, ax = pplt.subplots(ncols=2)
gs = fig1.gridspec.copy(left=5, wspace=0, right=5)
fig2 = pplt.figure()
fig2.add_subplots(gs)
fig = pplt.figure()
with pplt.tests.raises(ValueError):
fig.add_subplots(gs) # should raise error
return (fig1, fig2)
@pplt.tests.image_compare
def test_aligned_outer_guides():
"""
Test alignment adjustment.
"""
fig, ax = pplt.subplot()
h1 = ax.plot(np.arange(5), label='foo')
h2 = ax.plot(np.arange(5) + 1, label='bar')
h3 = ax.plot(np.arange(5) + 2, label='baz')
ax.legend(h1, loc='bottom', align='left')
ax.legend(h2, loc='bottom', align='right')
ax.legend(h3, loc='b', align='c')
ax.colorbar('magma', loc='right', align='top', shrink=0.4) # same as length
ax.colorbar('magma', loc='right', align='bottom', shrink=0.4)
ax.colorbar('magma', loc='left', align='top', length=0.6) # should offset
ax.colorbar('magma', loc='left', align='bottom', length=0.6)
ax.legend(h1, loc='top', align='right', pad='4pt', frame=False)
ax.format(title='Very long title', titlepad=6, titleloc='left')
def test_reference_aspect():
"""
Rigorous test of reference aspect ratio accuracy.
"""
# A simple test
refwidth = 1.5
fig, axs = pplt.subplots(ncols=2, refwidth=refwidth)
fig.auto_layout()
assert np.isclose(refwidth, axs[fig._refnum - 1]._get_size_inches()[0])
# A test with funky layout
refwidth = 1.5
fig, axs = pplt.subplots([[1, 1, 2, 2], [0, 3, 3, 0]], ref=3, refwidth=refwidth)
axs[1].panel_axes('left')
axs.format(xlocator=0.2, ylocator=0.2)
fig.auto_layout()
assert np.isclose(refwidth, axs[fig._refnum - 1]._get_size_inches()[0])
# A test with panels
refwidth = 2.0
fig, axs = pplt.subplots(
[[1, 1, 2], [3, 4, 5], [3, 4, 6]], hratios=(2, 1, 1), refwidth=refwidth
)
axs[2].panel_axes('right', width=0.5)
axs[0].panel_axes('bottom', width=0.5)
axs[3].panel_axes('left', width=0.5)
fig.auto_layout()
assert np.isclose(refwidth, axs[fig._refnum - 1]._get_size_inches()[0])