Esempio n. 1
0
    def plot_scatter(self, mask=None, ignore_zero=False, pop_name=True,
                     buffer=0.0, extend='neither', **kwargs):
        """Plot exposures geometry's value sum scattered over Earth's map.
        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 scatter matplotlib function, e.g.
                cmap='Greys'. Default: 'Wistia'
         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 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_scatter_from_array(value, coord, cbar_label, title, \
            pop_name, buffer, extend, proj=crs_epsg, **kwargs)
    def plot_scatter(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 scattered over Earth's map.
        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, optional): 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 scatter matplotlib function, e.g.
                cmap='Greys'. Default: 'Wistia'
         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 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_scatter_from_array(value,
                                             coord,
                                             cbar_label,
                                             title,
                                             pop_name,
                                             buffer,
                                             extend,
                                             proj=crs_epsg,
                                             axes=axis,
                                             figsize=figsize,
                                             adapt_fontsize=adapt_fontsize,
                                             **kwargs)
Esempio n. 3
0
 def test_geo_scatter_from_array(self):
     values = np.array([1, 2.0, 1, 1])
     coord = np.array([[-17, 178], [-10, 180], [-27, 175], [-16, 186]])
     var_name = 'test'
     title = 'test'
     projection = ccrs.PlateCarree()
     cmap = 'viridis'
     ax = u_plot.geo_scatter_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()