diff options
| author | Elliott Sales de Andrade <quantum.analyst@gmail.com> | 2017-06-21 19:46:38 -0400 |
|---|---|---|
| committer | Kristian Evers <kristianevers@gmail.com> | 2017-08-04 18:11:35 +0200 |
| commit | e44ad4942ca7076474e127ac6958a9ec06e995d0 (patch) | |
| tree | b70a9d81a747178ded4e1de95ab29312ce7f897a /docs/plot/plot.py | |
| parent | c974baa2238959cba65000ddd5dc89698e3421c9 (diff) | |
| download | PROJ-e44ad4942ca7076474e127ac6958a9ec06e995d0.tar.gz PROJ-e44ad4942ca7076474e127ac6958a9ec06e995d0.zip | |
Make better use of numpy and matplotlib.
Diffstat (limited to 'docs/plot/plot.py')
| -rw-r--r-- | docs/plot/plot.py | 36 |
1 files changed, 18 insertions, 18 deletions
diff --git a/docs/plot/plot.py b/docs/plot/plot.py index b1286f33..9d388375 100644 --- a/docs/plot/plot.py +++ b/docs/plot/plot.py @@ -166,8 +166,8 @@ def project_xy(x, y, proj_string): ''' Wrapper for project() that works with shapely.ops.transform(). ''' - a = project(zip(x, y), proj_string) - return zip(*a) + a = project(np.column_stack((x, y)), proj_string) + return a.T def meridian(lon, lat_min, lat_max): @@ -227,8 +227,7 @@ def plotproj(plotdef, data, outdir): ''' Plot map. ''' - fig = plt.figure() - axes = fig.add_subplot(111) + fig, axes = plt.subplots() bounds = (plotdef['lonmin'], plotdef['latmin'], plotdef['lonmax'], plotdef['latmax']) for geom in data.filter(bbox=bounds): @@ -244,9 +243,7 @@ def plotproj(plotdef, data, outdir): if plotdef['type'] == 'poly': if isinstance(temp_pol, MultiPolygon): - polys = [] - for polygon in temp_pol: - polys.append(resample_polygon(polygon)) + polys = [resample_polygon(polygon) for polygon in temp_pol] pol = MultiPolygon(polys) else: pol = resample_polygon(temp_pol) @@ -261,16 +258,18 @@ def plotproj(plotdef, data, outdir): axes.add_patch(patch) else: x, y = proj_geom.xy - plt.plot(x, y, color=COLOR_COAST, linewidth=0.5) + axes.plot(x, y, color=COLOR_COAST, linewidth=0.5) # Plot frame - frame = [] - frame.append(parallel(plotdef['latmin'], plotdef['lonmin'], plotdef['lonmax'])) - frame.append(parallel(plotdef['latmax'], plotdef['lonmin'], plotdef['lonmax'])) + frame = [ + parallel(plotdef['latmin'], plotdef['lonmin'], plotdef['lonmax']), + parallel(plotdef['latmax'], plotdef['lonmin'], plotdef['lonmax']), + ] for line in frame: line = project(line, plotdef['projstring']) - x, y = zip(*line) - plt.plot(x, y, '-k') + x = line[:, 0] + y = line[:, 1] + axes.plot(x, y, '-k') graticule = build_graticule( plotdef['lonmin'], @@ -282,8 +281,9 @@ def plotproj(plotdef, data, outdir): # Plot graticule for feature in graticule: feature = project(feature, plotdef['projstring']) - x, y = zip(*feature) - plt.plot(x, y, color=COLOR_GRAT, linewidth=0.4) + x = feature[:, 0] + y = feature[:, 1] + axes.plot(x, y, color=COLOR_GRAT, linewidth=0.4) axes.axis('off') font = { @@ -292,12 +292,12 @@ def plotproj(plotdef, data, outdir): 'style': 'italic', 'size': 12 } - plt.suptitle(plotdef['projstring'], fontdict=font) + fig.suptitle(plotdef['projstring'], fontdict=font) - plt.autoscale(tight=True) + axes.autoscale(tight=True) if not os.path.exists(outdir): os.makedirs(outdir) - plt.savefig(outdir + '/' + plotdef['filename'], dpi=300) + fig.savefig(outdir + '/' + plotdef['filename'], dpi=300) # Clean up fig = None |
