-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathtest_projections.py
More file actions
139 lines (119 loc) · 3.08 KB
/
Copy pathtest_projections.py
File metadata and controls
139 lines (119 loc) · 3.08 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
#!/usr/bin/env python3
"""
Test projection features.
"""
import cartopy.crs as ccrs
import matplotlib.pyplot as plt
import numpy as np
import proplot as pplt
state = np.random.RandomState(51423)
@pplt.tests.image_compare
def test_aspect_ratios():
"""
Test aspect ratio adjustments.
"""
fig, axs = pplt.subplots(ncols=2)
axs[0].format(aspect=1.5)
fig, axs = pplt.subplots(ncols=2, proj=('cart', 'cyl'), aspect=2)
axs[0].set_aspect(1)
if pplt.internals._version_mpl <= '3.2':
@pplt.tests.image_compare
def test_basemap_labels():
"""
Add basemap labels.
"""
fig, axs = pplt.subplots(ncols=2, proj='robin', refwidth=3, basemap=True)
axs.format(coast=True, labels='rt')
@pplt.tests.image_compare
def test_cartopy_labels():
"""
Add cartopy labels.
"""
fig, axs = pplt.subplots(ncols=2, proj='robin', refwidth=3)
axs.format(coast=True, labels=True)
axs[0].format(inlinelabels=True)
axs[1].format(rotatelabels=True)
@pplt.tests.image_compare
def test_cartopy_contours():
"""
Test bug with cartopy contours. Sometimes results in global coverage
with single color sometimes not.
"""
N = 10
fig = plt.figure(figsize=(5, 2.5))
ax = fig.add_subplot(projection=ccrs.Mollweide())
ax.coastlines()
x = np.linspace(-180, 180, N)
y = np.linspace(-90, 90, N)
z = state.rand(N, N) * 10 - 5
m = ax.contourf(
x, y, z,
transform=ccrs.PlateCarree(),
cmap='RdBu_r',
vmin=-5,
vmax=5,
)
fig.colorbar(m, ax=ax)
fig = pplt.figure()
ax = fig.add_subplot(
projection=pplt.Mollweide(),
extent='auto'
)
ax.coastlines()
N = 10
m = ax.contourf(
np.linspace(0, 180, N),
np.linspace(0, 90, N)[1::2],
state.rand(N // 2, N) * 10 + 5,
cmap='BuRd',
transform=pplt.PlateCarree(),
edgefix=False
)
fig.colorbar(m, ax=ax)
@pplt.tests.image_compare
def test_cartopy_manual():
"""
Test alternative workflow without classes.
"""
fig = pplt.figure()
proj = pplt.Proj('npstere')
# fig.add_axes([0.1, 0.1, 0.9, 0.9], proj='geo', map_projection=proj)
fig.add_subplot(111, proj='geo', land=True, map_projection=proj)
@pplt.tests.image_compare
def test_three_axes():
"""
Test basic 3D axes here.
"""
pplt.rc['tick.minor'] = False
fig, ax = pplt.subplots(proj='3d', outerpad=3)
@pplt.tests.image_compare
def test_projection_dicts():
"""
Test projection dictionaries.
"""
fig = pplt.figure(refnum=1)
a = [
[1, 0],
[1, 4],
[2, 4],
[2, 4],
[3, 4],
[3, 0]
]
fig.subplots(a, proj={1: 'cyl', 2: 'cart', 3: 'cart', 4: 'cart'})
@pplt.tests.image_compare
def test_polar_projections():
"""
Rigorously test polar features here.
"""
fig, ax = pplt.subplots(proj='polar')
ax.format(
rlabelpos=45,
thetadir=-1,
thetalines=90,
thetalim=(0, 270),
theta0='N',
r0=0,
rlim=(0.5, 1),
rlines=0.25,
)