def plot_hexbin(self, mask=None, ignore_zero=False, pop_name=True, buffer=0.0, extend='neither', **kwargs): """Plot exposures geometry's value sum binned over Earth's map. An other function for the bins can be set through the key reduce_C_function. The plot will we projected according to the current crs. Parameters: mask (np.array, optional): mask to apply to eai_exp plotted. ignore_zero (bool, optional): flag to indicate if zero and negative values are ignored in plot. Default: False pop_name (bool, optional): add names of the populated places buffer (float, optional): border to add to coordinates. Default: 0.0. extend (str, optional): extend border colorbar with arrows. [ 'neither' | 'both' | 'min' | 'max' ] kwargs (optional): arguments for hexbin matplotlib function, e.g. reduce_C_function=np.average. Default: reduce_C_function=np.sum Returns: matplotlib.figure.Figure, cartopy.mpl.geoaxes.GeoAxesSubplot """ crs_epsg, _ = self._get_transformation() title = self.tag.description cbar_label = 'Value (%s)' % self.value_unit if 'reduce_C_function' not in kwargs: kwargs['reduce_C_function'] = np.sum if mask is None: mask = np.ones((self.shape[0],), dtype=bool) if ignore_zero: pos_vals = self.value[mask].values > 0 else: pos_vals = np.ones((self.value[mask].values.size,), dtype=bool) value = self.value[mask][pos_vals].values coord = np.stack([self.latitude[mask][pos_vals].values, self.longitude[mask][pos_vals].values], axis=1) return u_plot.geo_bin_from_array(value, coord, cbar_label, title, \ pop_name, buffer, extend, proj=crs_epsg, **kwargs)
def plot_hexbin(self, mask=None, ignore_zero=False, pop_name=True, buffer=0.0, extend='neither', axis=None, figsize=(9, 13), adapt_fontsize=True, **kwargs): """Plot exposures geometry's value sum binned over Earth's map. An other function for the bins can be set through the key reduce_C_function. The plot will we projected according to the current crs. Parameters ---------- mask : np.array, optional mask to apply to eai_exp plotted. ignore_zero : bool, optional flag to indicate if zero and negative values are ignored in plot. Default: False pop_name : bool, optional add names of the populated places, by default True. buffer : float, optional border to add to coordinates. Default: 0.0. extend : str, optional extend border colorbar with arrows. [ 'neither' | 'both' | 'min' | 'max' ] axis : matplotlib.axes._subplots.AxesSubplot, optional axis to use figsize : tuple figure size for plt.subplots adapt_fontsize : bool, optional If set to true, the size of the fonts will be adapted to the size of the figure. Otherwise the default matplotlib font size is used. Default is True. kwargs : optional arguments for hexbin matplotlib function, e.g. reduce_C_function=np.average. Default: reduce_C_function=np.sum Returns ------- cartopy.mpl.geoaxes.GeoAxesSubplot """ crs_epsg, _ = u_plot.get_transformation(self.crs) title = self.tag.description cbar_label = 'Value (%s)' % self.value_unit if 'reduce_C_function' not in kwargs: kwargs['reduce_C_function'] = np.sum if mask is None: mask = np.ones((self.gdf.shape[0],), dtype=bool) if ignore_zero: pos_vals = self.gdf.value[mask].values > 0 else: pos_vals = np.ones((self.gdf.value[mask].values.size,), dtype=bool) value = self.gdf.value[mask][pos_vals].values coord = np.stack([self.gdf.latitude[mask][pos_vals].values, self.gdf.longitude[mask][pos_vals].values], axis=1) return u_plot.geo_bin_from_array(value, coord, cbar_label, title, pop_name, buffer, extend, proj=crs_epsg, axes=axis, figsize=figsize, adapt_fontsize=adapt_fontsize, **kwargs)
def test_geo_bin_from_array(self): values = np.array([1, 2.0, 5, 1]) coord = np.array([[-10, 17], [-30, 20], [5, 75], [-16, 20]]) var_name = 'test' title = 'test' projection = ccrs.PlateCarree() cmap = 'viridis' ax = u_plot.geo_bin_from_array(values, coord, var_name, title, pop_name=True, extend='neither', shapes=True, axes=None, proj=projection, figsize=(9, 13), cmap=cmap) self.assertEqual(var_name, ax.get_title()) self.assertAlmostEqual(np.max(values), ax.collections[0].colorbar.vmax) self.assertAlmostEqual(np.min(values), ax.collections[0].colorbar.vmin) self.assertEqual(cmap, ax.collections[0].cmap.name) plt.close()