Skip to content

Commit 87bebc5

Browse files
committed
Fix reference to missing example in FAQ
Solves GitHub issue #592.
1 parent 7bcca10 commit 87bebc5

File tree

3 files changed

+70
-63
lines changed

3 files changed

+70
-63
lines changed

CHANGELOG.md

+5
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ https://semver.org/spec/v2.0.0.html
2424
@YilongWang).
2525
- Fix `antialiased` argument being ignored in `Basemap.drawcounties` and
2626
`Basemap.readshapefile` (solves issue [#501], thanks to @TheFizzWare).
27+
- Fix wrong reference to `ireland.py` example in FAQ, which should be
28+
`hires.py` instead, and fix wrong use of locals and invalid syntax
29+
in this example (solves issue [#592], thanks to @timcoote).
2730

2831
## [1.3.8] - 2023-08-18
2932

@@ -991,6 +994,8 @@ https://semver.org/spec/v2.0.0.html
991994
- Fix glitches in drawing of parallels and meridians.
992995

993996

997+
[#592]:
998+
https://github.com/matplotlib/basemap/issues/592
994999
[#589]:
9951000
https://github.com/matplotlib/basemap/issues/589
9961001
[#583]:

FAQ

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,33 @@
1-
Q: It takes a long time to make a plot with the 'intermediate' or 'high'
1+
Q: It takes a long time to make a plot with the 'intermediate' or 'high'
22
resolution coastlines, how can I speed it up?
33

4-
A: There is a overhead in processing boundary datasets when a Basemap
5-
class in created, and this overhead can be significant for the higher
6-
resolution boundaries. If you are makeing many maps for the same region,
7-
you only need to create you Basemap class instance once, then re-use it
8-
for each plot. If the plots are being created by different scripts, you
9-
can save the Basemap class instance to a Pickle on disk, then read it in
10-
whatever script needs it (it's much faster to read a pickle from disk than
11-
it is to create the Basemap instance originally). The ireland.py example
4+
A: There is a overhead in processing boundary datasets when a Basemap
5+
class in created, and this overhead can be significant for the higher
6+
resolution boundaries. If you are makeing many maps for the same region,
7+
you only need to create you Basemap class instance once, then re-use it
8+
for each plot. If the plots are being created by different scripts, you
9+
can save the Basemap class instance to a Pickle on disk, then read it in
10+
whatever script needs it (it's much faster to read a pickle from disk than
11+
it is to create the Basemap instance originally). The hires.py example
1212
illustrates how to do this.
1313

14-
Q: I have my own boundary dataset that I would like to use, how do I use
14+
Q: I have my own boundary dataset that I would like to use, how do I use
1515
it in place of (or in addition to) the built-in basemap boundary datasets?
1616

17-
A: If your dataset is in ESRI shapefile format, this is relatively easy.
18-
Just create your Basemap class instance, then call the 'readshapefile'
19-
method on that instance to import your data. Setting 'drawbounds=True'
20-
will draw the boundaries in the shapefile. The fillstates.py example
17+
A: If your dataset is in ESRI shapefile format, this is relatively easy.
18+
Just create your Basemap class instance, then call the 'readshapefile'
19+
method on that instance to import your data. Setting 'drawbounds=True'
20+
will draw the boundaries in the shapefile. The fillstates.py example
2121
shows how to do this.
2222

23-
Q: How do I specify the map projection region if I don't know what the
23+
Q: How do I specify the map projection region if I don't know what the
2424
latitude and longitudes of the corners are?
2525

26-
A: As an alternative to specifying the lat/lon values for the upper-right
27-
and lower-left corners of the projection domain (using the llcrnrlat,
28-
llcrnrlon, urcrnrlat and urcrnrlon keywords) you can specify the center of
29-
the map projection domain (using the lat_0 and lon_0 keywords) and the
30-
width and height of the domain in map projection coordinates (meters)
31-
using the width and height keywords. Basemap will then calculate the
32-
corresponging values of llcrnrlat, llcrnrlon, urcrnrlat and urcrnrlon.
26+
A: As an alternative to specifying the lat/lon values for the upper-right
27+
and lower-left corners of the projection domain (using the llcrnrlat,
28+
llcrnrlon, urcrnrlat and urcrnrlon keywords) you can specify the center of
29+
the map projection domain (using the lat_0 and lon_0 keywords) and the
30+
width and height of the domain in map projection coordinates (meters)
31+
using the width and height keywords. Basemap will then calculate the
32+
corresponging values of llcrnrlat, llcrnrlon, urcrnrlat and urcrnrlon.
3333
Examples of this are given in the garp.py and setwh.py examples.

examples/hires.py

+43-41
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,51 @@
1-
from __future__ import (absolute_import, division, print_function)
1+
from __future__ import print_function
2+
3+
import time
4+
import pickle
25

3-
from mpl_toolkits.basemap import Basemap
46
import numpy as np
57
import matplotlib.pyplot as plt
6-
import pickle, time
8+
from mpl_toolkits.basemap import Basemap
9+
710

8-
# create figure with aqua background (will be oceans)
11+
# Create figure.
912
fig = plt.figure()
1013

11-
# create Basemap instance. Use 'high' resolution coastlines.
12-
t1 = time.clock()
13-
#m = Basemap(llcrnrlon=-10.5,llcrnrlat=49.5,urcrnrlon=3.5,urcrnrlat=59.5,
14-
# resolution='h',projection='tmerc',lon_0=-4,lat_0=0)
15-
m = Basemap(width=920000,height=1100000,
16-
resolution='f',projection='tmerc',lon_0=-4.2,lat_0=54.6)
17-
# make sure countries and rivers are loaded
18-
m.drawcountries()
19-
m.drawrivers()
20-
print(time.clock()-t1,' secs to create original Basemap instance')
21-
22-
# pickle the class instance.
23-
pickle.dump(m,open('map.pickle','wb'),-1)
24-
25-
# clear the figure
14+
# Create Basemap instance:
15+
# - Use 'full' resolution coastlines.
16+
# - Make sure that countries and rivers are loaded.
17+
t0 = time.time()
18+
bmap1 = Basemap(width=920000, height=1100000, resolution="f",
19+
projection="tmerc", lon_0=-4.2, lat_0=54.6)
20+
bmap1.drawcountries()
21+
bmap1.drawrivers()
22+
t1 = time.time()
23+
print("{0:.3f} secs to plot with a Basemap instance created at runtime".format(t1 - t0))
24+
25+
# Clear the figure.
2626
plt.clf()
27-
# read pickle back in and plot it again (should be much faster).
28-
t1 = time.clock()
29-
m2 = pickle.load(open('map.pickle','rb'))
30-
# draw coastlines and fill continents.
31-
m.drawcoastlines()
32-
# fill continents and lakes
33-
m.fillcontinents(color='coral',lake_color='aqua')
34-
# draw political boundaries.
35-
m.drawcountries(linewidth=1)
36-
# fill map projection region light blue (this will
37-
# paint ocean areas same color as lakes).
38-
m.drawmapboundary(fill_color='aqua')
39-
# draw major rivers.
40-
m.drawrivers(color='b')
41-
print(time.clock()-t1,' secs to plot using using a pickled Basemap instance')
42-
# draw parallels
43-
circles = np.arange(48,65,2).tolist()
44-
m.drawparallels(circles,labels=[1,1,0,0])
45-
# draw meridians
46-
meridians = np.arange(-12,13,2)
47-
m.drawmeridians(meridians,labels=[0,0,1,1])
48-
plt.title("High-Res British Isles",y=1.04)
27+
28+
# Pickle the class instance.
29+
with open("map.pickle", "wb") as fd:
30+
pickle.dump(bmap1, fd, protocol=-1)
31+
32+
# Read pickle back in and plot it again (should be much faster):
33+
# - Draw coastlines and fill continents and lakes.
34+
# - Draw political boundaries and rivers.
35+
# - Draw parallels and meridians.
36+
# - Draw map boundary and fill map background.
37+
t0 = time.time()
38+
with open("map.pickle", "rb") as fd:
39+
bmap2 = pickle.load(fd)
40+
bmap2.drawcoastlines()
41+
bmap2.fillcontinents(color="coral", lake_color="aqua")
42+
bmap2.drawcountries(linewidth=1)
43+
bmap2.drawrivers(color="b")
44+
bmap2.drawparallels(np.arange(48, 65, 2), labels=[1, 1, 0, 0])
45+
bmap2.drawmeridians(np.arange(-12, 13, 2), labels=[0, 0, 1, 1])
46+
bmap2.drawmapboundary(fill_color="aqua")
47+
t1 = time.time()
48+
print("{0:.3f} secs to plot with a pickled Basemap instance".format(t1 - t0))
49+
50+
plt.title("High-Res British Isles", y=1.04)
4951
plt.show()

0 commit comments

Comments
 (0)