def _setup_geometry(self): wpage, hpage = self.width, self.height ml, mr, mt, mb = self._expand_margins() wpage -= ml + mr hpage -= mt + mb wreg = self.radius * 2.0 hreg = self.radius * 2.0 if wpage >= hpage: wreg *= wpage/hpage else: hreg *= hpage/wpage self._corners = corners(self.lon, self.lat, wreg, hreg) west, east, south, north = extent(self.lon, self.lat, wreg, hreg, 10) x, y, z = ((west, east), (south, north), (-6000., 4500.)) xax = gmtpy.Ax(mode='min-max', approx_ticks=4.) yax = gmtpy.Ax(mode='min-max', approx_ticks=4.) zax = gmtpy.Ax(mode='min-max', inc=1000., label='Height', scaled_unit='km', scaled_unit_factor=0.001) scaler = gmtpy.ScaleGuru(data_tuples=[(x, y, z)], axes=(xax, yax, zax)) par = scaler.get_params() west = par['xmin'] east = par['xmax'] south = par['ymin'] north = par['ymax'] self._wesn = west, east, south, north self._scaler = scaler
def test_basic2(self): for version in gmtpy.all_installed_gmt_versions(): if version.startswith('5'): gmt = gmtpy.GMT(version=version, config={'MAP_FRAME_TYPE': 'fancy'}, eps_mode=True) else: gmt = gmtpy.GMT(version=version, config={'BASEMAP_TYPE': 'fancy'}) layout = gmt.default_layout() widget = layout.get_widget() xax = gmtpy.Ax(label='Lon', mode='min-max') yax = gmtpy.Ax(label='Lat', mode='min-max') scaler = gmtpy.ScaleGuru([([5, 15], [52, 58])], axes=(xax, yax)) par = scaler.get_params() lon0 = (par['xmin'] + par['xmax']) / 2. lat0 = (par['ymin'] + par['ymax']) / 2. sll = '%g/%g' % (lon0, lat0) widget['J'] = '-JM' + sll + '/%(width)gp' widget['J'] = '-JM' + sll + '/%(width)gp' scaler['B'] = \ '-B%(xinc)gg%(xinc)g:%(xlabel)s:' \ '/%(yinc)gg%(yinc)g:%(ylabel)s:WSen' aspect = gmtpy.aspect_for_projection(version, *(widget.J() + scaler.R())) aspect = 1.045 widget.set_aspect(aspect) gmt.pscoast(D='h', W='1p,red', *(widget.JXY() + scaler.R())) gmt.psbasemap(*(widget.JXY() + scaler.BR())) fname = 'gmtpy_test_basic2.png' fpath = self.fpath(fname) gmt.save(fpath, resolution=75, bbox=layout.bbox()) self.compare_with_ref(fname, 0.01, show=False)
def test_layout(self): x = num.linspace(0., math.pi * 6, 1001) y1 = num.sin(x) * 1e-9 y2 = 2.0 * num.cos(x) * 1e-9 xax = gmtpy.Ax(label='Time', unit='s') yax = gmtpy.Ax(label='Amplitude', unit='m', scaled_unit='nm', scaled_unit_factor=1e9, approx_ticks=5, space=0.05) guru = gmtpy.ScaleGuru([(x, y1), (x, y2)], axes=(xax, yax)) for version in gmtpy.all_installed_gmt_versions(): width = 8 * inch height = 3 * inch gmt = gmtpy.GMT(version=version, config_papersize=(width, height)) layout = gmt.default_layout() widget = layout.get_widget() gmt.draw_layout(layout) gmt.psbasemap(*(widget.JXY() + guru.RB(ax_projection=True))) gmt.psxy(in_columns=(x, y1), W='1p,red', *(widget.JXY() + guru.R())) gmt.psxy(in_columns=(x, y2), W='1p,blue', *(widget.JXY() + guru.R())) fname = 'gmtpy_test_layout.png' fpath = self.fpath(fname) gmt.save(fpath) self.compare_with_ref(fname, 0.01)
def test_grid_layout(self): for version in gmtpy.all_installed_gmt_versions(): gmt = gmtpy.GMT(version=version, config_papersize='a3') nx, ny = 2, 5 grid = gmtpy.GridLayout(nx, ny) layout = gmt.default_layout() layout.set_widget('center', grid) widgets = [] for iy in range(ny): for ix in range(nx): inner = gmtpy.FrameLayout() inner.set_fixed_margins(1. * cm * golden_ratio, 1. * cm * golden_ratio, 1. * cm, 1. * cm) grid.set_widget(ix, iy, inner) inner.set_vertical(0, (iy + 1.)) widgets.append(inner.get_widget('center')) gmt.draw_layout(layout) for widget in widgets: x = num.linspace(0., 10., 5) y = num.sin(x) xax = gmtpy.Ax(approx_ticks=4, snap=True) yax = gmtpy.Ax(approx_ticks=4, snap=True) guru = gmtpy.ScaleGuru([(x, y)], axes=(xax, yax)) gmt.psbasemap(*(widget.JXY() + guru.RB(ax_projection=True))) gmt.psxy(in_columns=(x, y), *(widget.JXY() + guru.R())) fname = 'gmtpy_test_grid_layout.png' fpath = self.fpath(fname) gmt.save(fpath, resolution=75) self.compare_with_ref(fname, 0.01)