<div dir="ltr">The `colorbar` method lives on the figure, not the axes.  This is because making the colorbar may re-arrange the layout of the axes in the parent figure and does not anything to the draw tree of `ax`.<div><br></div><div>sm = ax.hexbin(...)</div><div>fig.colorbar(sm, ..)</div><div><br></div><div>should work (<a href="http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure.colorbar">http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure.colorbar</a>).</div><div><br></div><div>Tom</div></div><br><div class="gmail_quote"><div dir="ltr">On Fri, Jan 8, 2016 at 7:03 AM Neal Becker <<a href="mailto:ndbecker2@gmail.com">ndbecker2@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">In the following script, in the call to hexbin, I can use<br>
ax.hexbin<br>
or<br>
plt.hexbin<br>
<br>
but in the call to colorbar, I can only use<br>
plt.colorbar<br>
not<br>
ax.colorbar<br>
<br>
This seems strangely inconsistent<br>
<br>
------------------------------<br>
import numpy as np<br>
from dill import load<br>
<br>
a,r = load (open ('test2.log.pickle', 'rb'))<br>
remod_2dhist = r['remod_2dhist']<br>
<br>
import matplotlib.pyplot as plt<br>
<br>
# from mpl_toolkits.mplot3d import Axes3D<br>
# from matplotlib import cm<br>
#import matplotlib as mpl<br>
mpl.rc('font', family='sans')<br>
<br>
fig = plt.figure()<br>
ax = fig.add_subplot(111)<br>
<br>
weights = []<br>
xs = []<br>
ys = []<br>
X, Y = remod_2dhist.get_axes()<br>
for i,x in enumerate (X):<br>
    for j,y in enumerate (Y):<br>
        if remod_2dhist.buckets[i,j] != 0:<br>
            weights.append (remod_2dhist.buckets[i,j])<br>
            xs.append (x)<br>
            ys.append (y)<br>
<br>
plt.hexbin (xs, ys, weights, mincnt=1, bins='log')<br>
cb = plt.colorbar()<br>
cb.set_label('log10(N)')<br>
ax.set_xlabel (r'demod $S/(N+I)$(dB) relative')<br>
ax.set_ylabel (r'remod mse(dB) absolute')<br>
plt.show()<br>
<br>
<br>
_______________________________________________<br>
Matplotlib-users mailing list<br>
<a href="mailto:Matplotlib-users@python.org" target="_blank">Matplotlib-users@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/matplotlib-users" rel="noreferrer" target="_blank">https://mail.python.org/mailman/listinfo/matplotlib-users</a><br>
</blockquote></div>