def get_can_draw_map(cube, dim_1_name, dim_2_name): """ Determines if the plot is a lat/lon plot by calling the iris.plot method _can_draw_map([coord1, coord2]). Returns a Boolean. Args: * cube The cube being plotted * dim_1_name The name of the first axis dimension (obtained from MainWindow.select_dimension_1.currentText()) * dim_2_name The name of the second axis dimension. Returns: * can_draw_map Boolean describing if the the plot is lat/lon or not. """ try: coord_1 = cube.coord(dim_1_name) coord_2 = cube.coord(dim_2_name) can_draw_map = iplt._can_draw_map([coord_1, coord_2]) if not can_draw_map: can_draw_map = iplt._can_draw_map([coord_2, coord_1]) except iris.exceptions.CoordinateNotFoundError: can_draw_map = False return can_draw_map
def _label(cube, mode, result=None, ndims=2, coords=None): """Puts labels on the current plot using the given cube.""" plt.title(_title(cube, with_units=False)) if result is not None: draw_edges = mode == iris.coords.POINT_MODE bar = plt.colorbar(result, orientation='horizontal', drawedges=draw_edges) has_known_units = not (cube.units.is_unknown() or cube.units.is_no_unit()) if has_known_units and cube.units != iris.unit.Unit('1'): # Use shortest unit representation for anything other than time if (not cube.units.is_time() and not cube.units.is_time_reference() and len(cube.units.symbol) < len(str(cube.units))): bar.set_label(cube.units.symbol) else: bar.set_label(cube.units) # Remove the tick which is put on the colorbar by default. bar.ax.tick_params(length=0) if coords is None: plot_defn = iplt._get_plot_defn(cube, mode, ndims) else: plot_defn = iplt._get_plot_defn_custom_coords_picked(cube, coords, mode, ndims=ndims) if ndims == 2: if not iplt._can_draw_map(plot_defn.coords): plt.ylabel(_title(plot_defn.coords[0], with_units=True)) plt.xlabel(_title(plot_defn.coords[1], with_units=True)) elif ndims == 1: plt.xlabel(_title(plot_defn.coords[0], with_units=True)) plt.ylabel(_title(cube, with_units=True)) else: raise ValueError('Unexpected number of dimensions (%s) given to _label.' % ndims)
def _label(cube, mode, result=None, ndims=2, coords=None): """Puts labels on the current plot using the given cube.""" plt.title(_title(cube, with_units=False)) if result is not None: draw_edges = mode == iris.coords.POINT_MODE bar = plt.colorbar(result, orientation='horizontal', drawedges=draw_edges) bar.set_label(cube.units) # Remove the tick which is put on the colorbar by default. bar.ax.tick_params(length=0) if coords is None: plot_defn = iplt._get_plot_defn(cube, mode, ndims) else: plot_defn = iplt._get_plot_defn_custom_coords_picked(cube, coords, mode, ndims=ndims) if ndims == 2: if not iplt._can_draw_map(plot_defn.coords): plt.ylabel(_title(plot_defn.coords[0], with_units=True)) plt.xlabel(_title(plot_defn.coords[1], with_units=True)) elif ndims == 1: plt.xlabel(_title(plot_defn.coords[0], with_units=True)) plt.ylabel(_title(cube, with_units=True)) else: raise ValueError('Unexpected number of dimensions (%s) given to _label.' % ndims)
def _label(cube, mode, result=None, ndims=2, coords=None, axes=None): """Puts labels on the current plot using the given cube.""" if axes is None: axes = plt.gca() axes.set_title(_title(cube, with_units=False)) if result is not None: draw_edges = mode == iris.coords.POINT_MODE bar = plt.colorbar(result, orientation='horizontal', drawedges=draw_edges) has_known_units = not (cube.units.is_unknown() or cube.units.is_no_unit()) if has_known_units and cube.units != cf_units.Unit('1'): # Use shortest unit representation for anything other than time if _use_symbol(cube.units): bar.set_label(cube.units.symbol) else: bar.set_label(cube.units) # Remove the tick which is put on the colorbar by default. bar.ax.tick_params(length=0) if coords is None: plot_defn = iplt._get_plot_defn(cube, mode, ndims) else: plot_defn = iplt._get_plot_defn_custom_coords_picked(cube, coords, mode, ndims=ndims) if ndims == 2: if not iplt._can_draw_map(plot_defn.coords): axes.set_ylabel(_title(plot_defn.coords[0], with_units=True)) axes.set_xlabel(_title(plot_defn.coords[1], with_units=True)) elif ndims == 1: axes.set_xlabel(_title(plot_defn.coords[0], with_units=True)) axes.set_ylabel(_title(cube, with_units=True)) else: msg = 'Unexpected number of dimensions ({}) given to ' \ '_label.'.format(ndims) raise ValueError(msg)