""" Specify contour levels ======================= Use :func:`clfdict()` to create a set of contour levels and contour lines to plot. """ import pygeode as pyg, numpy as np import pylab as pyl pyl.ioff() lat = pyg.regularlat(60) lon = pyg.regularlon(120) z = pyg.sin(2 * np.pi * lat / 180.)**10 + pyg.cos(10 + (2 * np.pi / 180.)**2 * lat * lon) * pyg.cos( 2 * np.pi * lat / 180.) ax = pyg.plot.AxesWrapper() contour_dict = pyg.clfdict(min=-1.2, axes=ax, cdelt=0.4, ndiv=3, nf=2, nl=1, extend='both', cmap='RdGy') pyg.vcontour(z, **contour_dict) ax.setp(title='Using helper function to set up contour levels')
""" import pylab as pyl pyl.ioff() import pygeode as pyg import numpy as np from pygeode.tutorial import t2 # Generate some data for a scatter plot N = 50 x_values = np.linspace(-1, 1, N) colors = np.random.rand(N) area = 1000 * np.random.rand(N) * (1 - abs(x_values)) x = pyg.NamedAxis(values=x_values, name='x') y = pyg.NamedAxis(values=x_values + np.random.rand(N), name='y') ax_scatter = pyg.vscatter(x, y, c=colors, s=area, alpha=0.5) # Make a vcontour ax_vcontour = pyg.vcontour(t2.Temp(pres=500, time='10 May 2012') * (pyg.cos(t2.lat)) * pyg.sin(t2.lon), cmap='Oranges') # Stitch the axes together side by side into a grid ax_both = pyg.plot.grid([[ax_scatter, ax_vcontour]]) pyl.ion() ax_both.render()
import pylab as pyl import pygeode as pyg, numpy as np t = pyg.ModelTime365(values = np.arange(100), units='days', startdate=dict(year=1, month=1)) y1 = pyg.exp(-t / 30.) * pyg.cos(2*np.pi * t / 20.) y2 = pyg.exp(-t / 30.) * pyg.sin(2*np.pi * t / 20.) y1 = y1.rename('y1') y2 = y2.rename('y2') pyl.ioff() ax = pyg.plot.AxesWrapper() pyg.vplot(y1, label='y1', c='r', lw=2, axes=ax) pyg.vplot(y2, label='y2', c='b', lw=2, axes=ax) ax.setp(title = 'Two lines', ylabel='') ax.setp_xaxis(major_formatter=pyg.timeticker.TimeFormatter(t, '$b')) ax.legend(loc='lower right', frameon=False) pyl.ion() ax.render(1)
Ft = f.integrate('lon', dx = lam, type='trapz') ax1 = pyg.showlines([1 - pyg.cosd(x), Fr, Fl, Ft], fmts = ['k+', '_', '_', 'x'], labels = [r'$1 - \cos x$', 'rectr', 'rectl', 'trapz'], fig=3) # Set panel title and axes labels ax1.setp(title = r"$\int_0^x \sin(x') dx'$", ylabel = '') # Adjust size and axis padding ax1.size = (4.1, 3) ax1.pad = [0.5, 0.3, 0.1, 0.4] # Example 2: f = cos(x) # Different integration directions f = pyg.cos(lam) Ff = f.integrate('lon', dx = lam, order=1) Fb = f.integrate('lon', dx = lam, order=-1) ax2 = pyg.showlines([f, Ff, Fb], fmts = ['k', '+', 'x'], labels = [r'$\cos x$', 'order = 1', 'order = -1'], fig=3) # Set panel title and axes labels ax2.setp(title = r"$\int_0^x \cos x' dx'$, $\int_{2\pi}^x \cos x' dx'$", ylabel = '') # Adjust size and axis padding ax2.size = (4.1, 3) ax2.pad = [0.5, 0.3, 0.1, 0.4] ax = pyg.plot.grid([[ax1], [ax2]])
""" Cartopy: Quiver plot on a regional projection ============================================= """ import pygeode as pyg, numpy as np, pylab as pyl from cartopy import crs as ccrs import cartopy # Construct dummy data for quivers lat = pyg.gausslat(40) lon = pyg.regularlon(80, origin=-180) x = pyg.sin(2*np.pi * lon / 180.) * pyg.exp(-(lat - 30)**2 / (2*10**2)) y = pyg.cos(4*np.pi * lon / 180.) * pyg.exp(-(lat - 40)**2 / (4*10**2)) pyl.ioff() # Build CartopyAxis for a Lambert Conformal projection prj = dict(central_longitude=-90., central_latitude = 39.) ax = pyg.plot.CartopyAxes(projection = 'LambertConformal', prj_args = prj) ax.size = [6., 5.1] # Add ocean ax.add_feature(cartopy.feature.OCEAN) # Add quiver plot pyg.vquiver(x, y, axes=ax, width = 0.005) # Set plot title ax.setp(title = 'Lambert Conformal')