Skip to content

Commit c91ac1a

Browse files
author
Jeff Whitaker
committed
added hexbin method.
1 parent 4941993 commit c91ac1a

File tree

2 files changed

+48
-0
lines changed

2 files changed

+48
-0
lines changed

Changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
version 1.0.3 (not yet released)
2+
* added hexbin method.
23
* drawmapboundary now uses axes bgcolor as default fill_color. If
34
no color fill wanted, set fill_color='none' (a string).
45
* clip coastlines for nplaea,npaeqd,splaea,spaeqd in stereographic

lib/mpl_toolkits/basemap/__init__.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3048,6 +3048,53 @@ def pcolormesh(self,x,y,data,**kwargs):
30483048
ax.set_frame_on(False)
30493049
return ret
30503050

3051+
def hexbin(self,x,y,**kwargs):
3052+
"""
3053+
Make a hexagonal binning plot of x versus y, where x, y are 1-D
3054+
sequences of the same length, N. If C is None (the default), this is a
3055+
histogram of the number of occurences of the observations at
3056+
(x[i],y[i]).
3057+
3058+
If C is specified, it specifies values at the coordinate (x[i],y[i]).
3059+
These values are accumulated for each hexagonal bin and then reduced
3060+
according to reduce_C_function, which defaults to numpy?s mean function
3061+
(np.mean). (If C is specified, it must also be a 1-D sequence of the
3062+
same length as x and y.)
3063+
3064+
x, y and/or C may be masked arrays, in which case only unmasked points
3065+
will be plotted.
3066+
3067+
(see matplotlib.pyplot.hexbin documentation).
3068+
3069+
Extra keyword ``ax`` can be used to override the default axis instance.
3070+
3071+
Other \**kwargs passed on to matplotlib.pyplot.hexbin
3072+
"""
3073+
ax, plt = self._ax_plt_from_kw(kwargs)
3074+
# allow callers to override the hold state by passing hold=True|False
3075+
b = ax.ishold()
3076+
h = kwargs.pop('hold',None)
3077+
if h is not None:
3078+
ax.hold(h)
3079+
try:
3080+
# make x,y masked arrays
3081+
# (masked where data is outside of projection limb)
3082+
x = ma.masked_values(np.where(x > 1.e20,1.e20,x), 1.e20)
3083+
y = ma.masked_values(np.where(y > 1.e20,1.e20,y), 1.e20)
3084+
ret = ax.hexbin(x,y,**kwargs)
3085+
except:
3086+
ax.hold(b)
3087+
raise
3088+
ax.hold(b)
3089+
# reset current active image (only if pyplot is imported).
3090+
if plt:
3091+
plt.sci(ret)
3092+
# clip for round polar plots.
3093+
if self.round: ret = self._clipcircle(ax,ret)
3094+
# set axes limits to fit map region.
3095+
self.set_axes_limits(ax=ax)
3096+
return ret
3097+
30513098
def contour(self,x,y,data,*args,**kwargs):
30523099
"""
30533100
Make a contour plot over the map

0 commit comments

Comments
 (0)