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

Skip to content

Require basemap to build docs #6243

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Apr 1, 2016
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Basemap is now a dependency of document building
  • Loading branch information
jenshnielsen committed Mar 30, 2016
commit f7fdaf874a52f81098d2dd254dd6dcedfafa5bb1
2 changes: 2 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,8 @@ install:
if [[ $BUILD_DOCS == true ]]; then
pip install $PRE numpydoc ipython jsonschema mistune colorspacious
pip install -q $PRE linkchecker
# Installing basemap from github until it's back on pypi
pip install https://github.com/matplotlib/basemap/archive/v1.0.7rel.tar.gz
wget https://github.com/google/fonts/blob/master/ofl/felipa/Felipa-Regular.ttf?raw=true -O Felipa-Regular.ttf
wget http://mirrors.kernel.org/ubuntu/pool/universe/f/fonts-humor-sans/fonts-humor-sans_1.0-1_all.deb
mkdir -p tmp
Expand Down
52 changes: 20 additions & 32 deletions doc/pyplots/plotmap.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,29 @@
import matplotlib.pyplot as plt
import numpy as np

try:
from mpl_toolkits.basemap import Basemap
have_basemap = True
except ImportError:
have_basemap = False
from mpl_toolkits.basemap import Basemap


def plotmap():
# create figure
fig = plt.figure(figsize=(8,8))
fig = plt.figure(figsize=(8, 8))
# set up orthographic map projection with
# perspective of satellite looking down at 50N, 100W.
# use low resolution coastlines.
map = Basemap(projection='ortho',lat_0=50,lon_0=-100,resolution='l')
map = Basemap(projection='ortho', lat_0=50, lon_0=-100, resolution='l')
# lat/lon coordinates of five cities.
lats=[40.02,32.73,38.55,48.25,17.29]
lons=[-105.16,-117.16,-77.00,-114.21,-88.10]
cities=['Boulder, CO','San Diego, CA',
'Washington, DC','Whitefish, MT','Belize City, Belize']
lats = [40.02, 32.73, 38.55, 48.25, 17.29]
lons = [-105.16, -117.16, -77.00, -114.21, -88.10]
cities = ['Boulder, CO', 'San Diego, CA',
'Washington, DC', 'Whitefish, MT', 'Belize City, Belize']
# compute the native map projection coordinates for cities.
xc,yc = map(lons,lats)
xc, yc = map(lons, lats)
# make up some data on a regular lat/lon grid.
nlats = 73; nlons = 145; delta = 2.*np.pi/(nlons-1)
lats = (0.5*np.pi-delta*np.indices((nlats,nlons))[0,:,:])
lons = (delta*np.indices((nlats,nlons))[1,:,:])
nlats = 73
nlons = 145
delta = 2.*np.pi/(nlons-1)
lats = (0.5*np.pi-delta*np.indices((nlats,nlons))[0, :, :])
lons = (delta*np.indices((nlats, nlons))[1, :, :])
wave = 0.75*(np.sin(2.*lats)**8*np.cos(4.*lons))
mean = 0.5*np.cos(2.*lats)*((np.sin(2.*lats))**2 + 2.)
# compute native map projection coordinates of lat/lon grid.
Expand All @@ -34,28 +32,18 @@ def plotmap():
# draw map boundary
map.drawmapboundary(color="0.9")
# draw graticule (latitude and longitude grid lines)
map.drawmeridians(np.arange(0,360,30),color="0.9")
map.drawparallels(np.arange(-90,90,30),color="0.9")
map.drawmeridians(np.arange(0, 360, 30), color="0.9")
map.drawparallels(np.arange(-90, 90, 30), color="0.9")
# plot filled circles at the locations of the cities.
map.plot(xc,yc,'wo')
map.plot(xc, yc, 'wo')
# plot the names of five cities.
for name,xpt,ypt in zip(cities,xc,yc):
plt.text(xpt+100000,ypt+100000,name,fontsize=9,color='w')
for name, xpt, ypt in zip(cities, xc, yc):
plt.text(xpt+100000, ypt+100000, name, fontsize=9, color='w')
# contour data over the map.
cs = map.contour(x,y,wave+mean,15,linewidths=1.5)
cs = map.contour(x, y, wave+mean, 15, linewidths=1.5)
# draw blue marble image in background.
# (downsample the image by 50% for speed)
map.bluemarble(scale=0.5)

def plotempty():
# create figure
fig = plt.figure(figsize=(8,8))
fig.text(0.5, 0.5, "Sorry, could not import Basemap",
horizontalalignment='center')

if have_basemap:
plotmap()
else:
plotempty()
plotmap()
plt.show()