def _goplot(self, sender): """Create the cube_browser.Plot2D and cube_browser.Browser""" IPython.display.clear_output() fig = plt.figure(figsize=(16, 7)) sub_plots = 110 if self._subplots.value == 2: sub_plots = 120 confs = [] for spl, pc in enumerate(self.plot_controls): spl += 1 cube = None if pc.cube_picker.value is not None: cube = self.cubes[pc.cube_picker.value] if cube and spl <= self._subplots.value: pc_x_name = pc.x_coord.value pc_y_name = pc.y_coord.value x_coords = cube.coords(axis='X', dim_coords=True) if len(x_coords) == 1: x_name = x_coords[0].name() else: x_name = None y_coords = cube.coords(axis='Y', dim_coords=True) if len(y_coords) == 1: y_name = y_coords[0].name() else: y_name = None if x_name == pc_x_name and y_name == pc_y_name: proj = iplt.default_projection(cube) or ccrs.PlateCarree() ax = fig.add_subplot(sub_plots + spl, projection=proj) # If the spatial extent is small, use high-res coastlines extent = iplt.default_projection_extent(cube) x0, y0 = ccrs.PlateCarree().transform_point(extent[0], extent[2], proj) x1, y1 = ccrs.PlateCarree().transform_point(extent[1], extent[3], proj) if x1-x0 < 20 and y1-y0 < 20: ax.coastlines(resolution='10m') elif x1-x0 < 180 and y1-y0 < 90: ax.coastlines(resolution='50m') else: ax.coastlines() else: ax = plt.gca() ax = fig.add_subplot(sub_plots+spl) plot_type = pc.plot_type coords = [pc_x_name, pc_y_name] confs.append(plot_type.value(cube, ax, coords=coords, **pc.mpl_kwargs)) title = cube.name().replace('_', ' ').capitalize() ax.set_title(title) self.browser = cube_browser.Browser(confs) self.browser.on_change(None) # For each PlotControl, assign the plot's mpl_kwargs back to # that PlotControl. for pc, plot in zip(self.plot_controls, confs): pc.mpl_kwargs = plot.kwargs self._plot_container.children = [self.browser.form]
def test_simple(self): # First sub-plot plt.subplot(221) plt.title('Default') iplt.contourf(self.cube) plt.gca().coastlines() # Second sub-plot plt.subplot(222, projection=ccrs.Mollweide(central_longitude=120)) plt.title('Molleweide') iplt.contourf(self.cube) plt.gca().coastlines() # Third sub-plot (the projection part is redundant, but a useful # test none-the-less) ax = plt.subplot(223, projection=iplt.default_projection(self.cube)) plt.title('Native') iplt.contour(self.cube) ax.coastlines() # Fourth sub-plot ax = plt.subplot(2, 2, 4, projection=ccrs.PlateCarree()) plt.title('PlateCarree') iplt.contourf(self.cube) ax.coastlines() self.check_graphic()
def test_default_projection_and_extent(self): self.assertEqual(iplt.default_projection(self.cube), ccrs.RotatedPole(357.5 - 180, 37.5)) np_testing.assert_array_almost_equal( iplt.default_projection_extent(self.cube), (313.01998901, 391.11999512, -22.48999977, 24.80999947))
def test_default_projection_and_extent(self): self.assertEqual(iplt.default_projection(self.cube), ccrs.RotatedPole(357.5 - 180, 37.5, globe=_DEFAULT_GLOBE)) np_testing.assert_array_almost_equal( iplt.default_projection_extent(self.cube), (313.01998901, 391.11999512, -22.48999977, 24.80999947))
def test_default_projection_and_extent(self): self.assertEqual(iplt.default_projection(self.cube), ccrs.RotatedPole(357.5 - 180, 37.5)) np_testing.assert_array_almost_equal( iplt.default_projection_extent(self.cube), (3.59579163e+02, 3.59669159e+02, -1.28250003e-01, -3.82499993e-02), decimal=3)
def test_default_projection_and_extent(self): self.assertEqual(iplt.default_projection(self.cube), ccrs.RotatedPole(357.5 - 180, 37.5, globe=_DEFAULT_GLOBE)) np_testing.assert_array_almost_equal( iplt.default_projection_extent(self.cube), (3.59579163e+02, 3.59669159e+02, -1.28250003e-01, -3.82499993e-02), decimal=3)
def test_default_projection_and_extent(self): self.assertEqual(iplt.default_projection(self.cube), ccrs.PlateCarree()) np_testing.assert_array_almost_equal( iplt.default_projection_extent(self.cube), [0., 360., -89.99995422, 89.99998474]) np_testing.assert_array_almost_equal( iplt.default_projection_extent( self.cube, mode=iris.coords.BOUND_MODE), [-1.875046, 358.124954, -91.24995422, 91.24998474])
def test_default_projection_and_extent(self): self.assertEqual(iplt.default_projection(self.cube), ccrs.PlateCarree()) np_testing.assert_array_almost_equal( iplt.default_projection_extent(self.cube), [0., 360., -89.99995422, 89.99998474]) np_testing.assert_array_almost_equal( iplt.default_projection_extent(self.cube, mode=iris.coords.BOUND_MODE), [-1.875046, 358.124954, -90, 90])
def test(self): projection = iplt.default_projection(self.cube) ax = plt.subplot(111, projection=projection) plot = Contourf(self.cube, ax, coords=self.coords) for index in range(self.cube.shape[0]): element = plot(time=index) self.assertIsInstance(element, QuadContourSet) self.assertEqual(element, plot.element) self.assertIsInstance(plot.axes, GeoAxesSubplot) self.assertEqual(ax, plot.axes) self.assertEqual(self.cube[index], plot.subcube)
def test_default_projection_and_extent(self): self.assertEqual( iplt.default_projection(self.cube), ccrs.PlateCarree(globe=self.cube.coord_system( "CoordSystem").as_cartopy_globe()), ) np_testing.assert_array_almost_equal( iplt.default_projection_extent(self.cube), [0.0, 360.0, -89.99995422, 89.99998474], ) np_testing.assert_array_almost_equal( iplt.default_projection_extent(self.cube, mode=iris.coords.BOUND_MODE), [-1.875046, 358.124954, -90, 90], )
def _goplot(self, sender): """Create the cube_browser.Plot2D and cube_browser.Browser""" IPython.display.clear_output() fig = plt.figure(figsize=(12, 6)) sub_plots = 110 if self._subplots.value == 2: sub_plots = 120 confs = [] for spl, pc in enumerate(self.plot_controls): spl += 1 cube = pc.cube_picker.value if cube and spl <= self._subplots.value: pc_x_name = pc.x_coord.value pc_y_name = pc.y_coord.value x_name = cube.coord(axis='X').name() y_name = cube.coord(axis='Y').name() if x_name == pc_x_name and y_name == pc_y_name: proj = iplt.default_projection(cube) or ccrs.PlateCarree() ax = fig.add_subplot(sub_plots + spl, projection=proj) ax.coastlines() else: ax = plt.gca() ax = fig.add_subplot(sub_plots + spl) plot_type = pc.plot_type coords = [pc_x_name, pc_y_name] confs.append( plot_type.value(cube, ax, coords=coords, **pc.mpl_kwargs)) title = cube.name().replace('_', ' ').capitalize() ax.set_title(title) self.browser = cube_browser.Browser(confs) self.browser.on_change(None) # For each PlotControl, assign the plot's mpl_kwargs back to # that PlotControl. for pc, plot in zip(self.plot_controls, confs): pc.mpl_kwargs = plot.kwargs self._plot_container.children = [self.browser.form]
def _goplot(self, sender): """Create the cube_browser.Plot2D and cube_browser.Browser""" IPython.display.clear_output() fig = plt.figure(figsize=(12, 6)) sub_plots = 110 if self._subplots.value == 2: sub_plots = 120 confs = [] for spl, pc in enumerate(self.plot_controls): spl += 1 cube = pc.cube_picker.value if cube and spl <= self._subplots.value: pc_x_name = pc.x_coord.value pc_y_name = pc.y_coord.value x_name = cube.coord(axis='X').name() y_name = cube.coord(axis='Y').name() if x_name == pc_x_name and y_name == pc_y_name: proj = iplt.default_projection(cube) or ccrs.PlateCarree() ax = fig.add_subplot(sub_plots + spl, projection=proj) ax.coastlines() else: ax = plt.gca() ax = fig.add_subplot(sub_plots+spl) plot_type = pc.plot_type coords = [pc_x_name, pc_y_name] confs.append(plot_type.value(cube, ax, coords=coords, **pc.mpl_kwargs)) title = cube.name().replace('_', ' ').capitalize() ax.set_title(title) self.browser = cube_browser.Browser(confs) self.browser.on_change(None) # For each PlotControl, assign the plot's mpl_kwargs back to # that PlotControl. for pc, plot in zip(self.plot_controls, confs): pc.mpl_kwargs = plot.kwargs self._plot_container.children = [self.browser.form]
def setUp(self): self.cube = realistic_3d() self.coords = ('grid_longitude', 'grid_latitude') self.projection = iplt.default_projection(self.cube)