-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathiris_Chapter7211.py
48 lines (34 loc) · 1.26 KB
/
iris_Chapter7211.py
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
#!/usr/bin/env python3
""" 7.2.1.1. Multi-line plot"""
"""Multi-line temperature profile plot"""
import matplotlib.pyplot as plt
import iris
import iris.plot as iplt
import iris.quickplot as qplt
def main():
fname = iris.sample_data_path('air_temp.pp')
# Load exactly one cube from the given file
temperature = iris.load_cube(fname)
# We only want a small number of latitudes, so filter some out
# using "extract"
temperature = temperature.extract(
iris.Constraint(latitude=lambda cell: 68 <= cell < 78))
# lat = temperature.coord('latitude')
# b = lat.points
for cube in temperature.slices('longitude'):
# Create a string label to identify this cube (i.e. latitude: value)
cube_label = 'latitude: %s' % cube.coord('latitude').points[0]
# Plot the cube, and associate it with a label
qplt.plot(cube, label=cube_label)
# Add the legend with 2 columns
plt.legend(ncol=2)
# Put a grid on the plot
plt.grid(True)
# Tell matplotlib not to extend the plot axes range to nicely
# rounded numbers
plt.axis('tight')
# Finally, show it
iplt.show()
# for the script is run from the comand line
if __name__ == '__main':
main()