Closed aleaf closed 9 years ago
I still suck at GitHub. See code below. Fixes the following items: 1). sets extent so hexbin x and y axis can be the same 2.) sets mincnt = 1 so bins with less than one are not colored 3.) formats tick labels on colorbar so that when bins = 'log' transforms out of log. And don't have to label as log10 bin counts. ` class HexbinPlot(One2onePlot): """Makes a hexbin plot of two dataframe columns, pyplot.hexbin"""
def _make_plot(self):
# overrides _make_plot() method in One2onePlot; inherits everything else
x = self.df[self.df['Group'].isin(self.groups)]['Measured'].values
y = self.df[self.df['Group'].isin(self.groups)]['Modelled'].values
self.min, self.max = np.min([x, y]), np.max([x, y])
# default keyword settings, which can be overriden by submitted keywords
kwds = {'bins': 'log', 'alpha': 1.0, 'edgecolors': 'none'}
kwds.update(self.kwds)
self.kwds = kwds
plt.hexbin(x, y, extent = (self.min, self.max, self.min, self.max), mincnt = 1, **self.kwds)
#plot one2one line
line_kwds = dict(color='k', alpha=0.5, zorder=1)
line_kwds.update(self.line_kwds)
plt.plot(np.arange(self.min, self.max+1), np.arange(self.min, self.max+1), **line_kwds)
#self.ax.set_ylim(np.min(y), np.max(y))
#self.ax.set_xlim(self.min, self.max)
def _make_legend(self):
if self.legend:
# put this here for now, may want to restructure later
cb = plt.colorbar()
if self.kwds['bins'] == 'log':
# Reformat the lables out of log
def log_trans(x, pos):
'The two args are the value and tick position'
return '%d' % (10**x)
cb.formatter = mpl.ticker.FuncFormatter(log_trans)
cb.update_ticks()
cb.set_label('Bin counts')
#cb.set_label('Log$\mathregular{_{10}}$ bin counts')
else:
cb.set_label('Bin counts')
`
Evan, good suggestions. I incorporated them into the last push.
working on the plotting structure. Trying to streamline things as I go and prune or add parameters where needed. Still need to get sphinx set up and figure out how to streamline the documentation workflow so that docstrings show up on the methods, but can be edited within their respective classes.
Check One2one.ipynb for demonstration of hexbin.