from __future__ import division import numpy as np import scipy.io as sio %matplotlib inline import matplotlib.pyplot as plt import matplotlib.patches as patches topo_datastruct = sio.loadmat('/ocean/rich/more/mmapbase/bcgeo/PNW.mat') coast={} coast['lat'] = topo_datastruct['ncst'][:,1] coast['lon'] = topo_datastruct['ncst'][:,0] k=topo_datastruct['k'] Area=topo_datastruct['Area'] print topo_datastruct['data_source'] def separate_polygons(a): return [a[s] for s in np.ma.clump_unmasked(np.ma.masked_invalid(a))] poly_lats = separate_polygons(coast['lat']) poly_lons = separate_polygons(coast['lon']) fig,ax=plt.subplots(1,1) for x,y in zip(poly_lons,poly_lats): poly=zip(x,y) ax.add_patch(patches.Polygon(poly,closed=True,facecolor='burlywood')) ax.set_xlim([-126,-121]) ax.set_ylim([48,51]) fig.savefig('test_all.svg') ! ls -lh test_all.svg fig.savefig('test_all.png') ! ls -lh test_all.png print coast['lon'][k[1]-2] fig,ax=plt.subplots(1,1) for ks,ke,A in zip(k[0:-1],k[1:],Area[0,:]): if A > 1e-4: poly=zip(coast['lon'][ks:ke-2],coast['lat'][ks:ke-2]) ax.add_patch(patches.Polygon(poly,closed=True,facecolor='burlywood',rasterized=True)) ax.set_xlim([-126,-121]) ax.set_ylim([48,51]) fig.savefig('test.svg') ! ls -lh test.svg import SVGCompress SVGCompress.compress_by_method('test_all.svg','merge',outputfile='test_all_compress.svg') ls -lh test_all.svg from salishsea_tools.nowcast import figures import netCDF4 as nc grid_B=nc.Dataset('/data/nsoontie/MEOPAR/NEMO-forcing/grid/bathy_meter_SalishSea2.nc') reload(figures) fig,ax=plt.subplots(1,1) figures.plot_map(ax,grid_B,topo_datastruct,'full',0,0) fig.savefig('test2.svg') ! ls -lh test2.svg