Skip to content

Commit 3d93b81

Browse files
committed
change plot binhex properties
1 parent 6adef5a commit 3d93b81

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

climada/entity/exposures/base.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ def check(self):
129129
self._check_defaults(num_exp)
130130

131131
def plot(self, ignore_zero=True, pop_name=True, buffer_deg=1.0,
132-
**kwargs):
132+
extend='neither', **kwargs):
133133
"""Plot exposures values sum binned over Earth's map.
134134
135135
Parameters:
@@ -138,6 +138,8 @@ def plot(self, ignore_zero=True, pop_name=True, buffer_deg=1.0,
138138
pop_name (bool, optional): add names of the populated places
139139
buffer_deg (float, optional): border to add to coordinates.
140140
Default: 1.0.
141+
extend (str, optional): extend border colorbar with arrows.
142+
[ 'neither' | 'both' | 'min' | 'max' ]
141143
kwargs (optional): arguments for hexbin matplotlib function
142144
143145
Returns:
@@ -147,9 +149,13 @@ def plot(self, ignore_zero=True, pop_name=True, buffer_deg=1.0,
147149
cbar_label = 'Value (%s)' % self.value_unit
148150
if 'reduce_C_function' not in kwargs:
149151
kwargs['reduce_C_function'] = np.sum
150-
152+
if ignore_zero:
153+
pos_vals = self.value > 0
154+
return plot.geo_bin_from_array(self.value[pos_vals], \
155+
self.coord[pos_vals, :], cbar_label, title, pop_name, \
156+
buffer_deg, extend, **kwargs)
151157
return plot.geo_bin_from_array(self.value, self.coord, cbar_label, \
152-
title, pop_name, buffer_deg, ignore_zero, **kwargs)
158+
title, pop_name, buffer_deg, extend, **kwargs)
153159

154160
def read(self, files, descriptions='', var_names=None):
155161
"""Read and check exposures.

climada/util/plot.py

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@
2626
# Maximum number of bins in geo_bin_from_array
2727
MAX_BINS = 200
2828

29-
def geo_bin_from_array(array_sub, geo_coord, var_name, title, pop_name=True,
30-
buffer_deg=BUFFER_DEG, ignore_zero=False, **kwargs):
29+
def geo_bin_from_array(array_sub, geo_coord, var_name, title, pop_name=True,\
30+
buffer_deg=BUFFER_DEG, extend='neither', **kwargs):
3131
"""Plot array values binned over input coordinates.
3232
3333
Parameters:
@@ -45,7 +45,8 @@ def geo_bin_from_array(array_sub, geo_coord, var_name, title, pop_name=True,
4545
array_sub.
4646
pop_name (bool, optional): add names of the populated places.
4747
buffer_deg (float, optional): border to add to coordinates
48-
ignore_zero (bool, optional): ignore zero and negative values
48+
extend (str, optional): extend border colorbar with arrows.
49+
[ 'neither' | 'both' | 'min' | 'max' ]
4950
kwargs (optional): arguments for hexbin matplotlib function
5051
5152
Returns:
@@ -70,13 +71,6 @@ def geo_bin_from_array(array_sub, geo_coord, var_name, title, pop_name=True,
7071
if coord.shape[0] != array_im.size:
7172
raise ValueError("Size mismatch in input array: %s != %s." % \
7273
(coord.shape[0], array_im.size))
73-
if ignore_zero and 0 in array_im:
74-
pos_vals = array_im > 0
75-
array_im = array_im[pos_vals]
76-
coord = coord[pos_vals, :]
77-
kwargs_cbar = {'extend':'min'}
78-
else:
79-
kwargs_cbar = {}
8074

8175
# Binned image with coastlines
8276
extent = get_borders(coord)
@@ -96,7 +90,7 @@ def geo_bin_from_array(array_sub, geo_coord, var_name, title, pop_name=True,
9690
cbax = make_axes_locatable(axis).append_axes('right', size="6.5%", \
9791
pad=0.1, axes_class=plt.Axes)
9892
cbar = plt.colorbar(hex_bin, cax=cbax, orientation='vertical',
99-
**kwargs_cbar)
93+
extend=extend)
10094
cbar.set_label(name)
10195
axis.set_title(tit)
10296

0 commit comments

Comments
 (0)