strange inconsistency

In the following script, in the call to hexbin, I can use
ax.hexbin
or
plt.hexbin

but in the call to colorbar, I can only use
plt.colorbar
not
ax.colorbar

This seems strangely inconsistent

···

------------------------------
import numpy as np
from dill import load

a,r = load (open ('test2.log.pickle', 'rb'))
remod_2dhist = r['remod_2dhist']

import matplotlib.pyplot as plt

# from mpl_toolkits.mplot3d import Axes3D
# from matplotlib import cm
#import matplotlib as mpl
mpl.rc('font', family='sans')

fig = plt.figure()
ax = fig.add_subplot(111)

weights = []
xs = []
ys = []
X, Y = remod_2dhist.get_axes()
for i,x in enumerate (X):
    for j,y in enumerate (Y):
        if remod_2dhist.buckets[i,j] != 0:
            weights.append (remod_2dhist.buckets[i,j])
            xs.append (x)
            ys.append (y)

plt.hexbin (xs, ys, weights, mincnt=1, bins='log')
cb = plt.colorbar()
cb.set_label('log10(N)')
ax.set_xlabel (r'demod $S/(N+I)$(dB) relative')
ax.set_ylabel (r'remod mse(dB) absolute')
plt.show()

Le vendredi 08 janvier 2016, Neal Becker a ?crit :

In the following script, in the call to hexbin, I can use
ax.hexbin
or
plt.hexbin

but in the call to colorbar, I can only use
plt.colorbar
not
ax.colorbar

This seems strangely inconsistent

Because the colorbar is not attached to the axes instance, but to the
figure instance as it can illustrate any Image, ContourSet, etc... in
the figure.

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`.

sm = ax.hexbin(...)
fig.colorbar(sm, ..)

should work (
http://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure.colorbar
).

Tom

···

On Fri, Jan 8, 2016 at 7:03 AM Neal Becker <ndbecker2 at gmail.com> wrote:

In the following script, in the call to hexbin, I can use
ax.hexbin
or
plt.hexbin

but in the call to colorbar, I can only use
plt.colorbar
not
ax.colorbar

This seems strangely inconsistent

------------------------------
import numpy as np
from dill import load

a,r = load (open ('test2.log.pickle', 'rb'))
remod_2dhist = r['remod_2dhist']

import matplotlib.pyplot as plt

# from mpl_toolkits.mplot3d import Axes3D
# from matplotlib import cm
#import matplotlib as mpl
mpl.rc('font', family='sans')

fig = plt.figure()
ax = fig.add_subplot(111)

weights =
xs =
ys =
X, Y = remod_2dhist.get_axes()
for i,x in enumerate (X):
    for j,y in enumerate (Y):
        if remod_2dhist.buckets[i,j] != 0:
            weights.append (remod_2dhist.buckets[i,j])
            xs.append (x)
            ys.append (y)

plt.hexbin (xs, ys, weights, mincnt=1, bins='log')
cb = plt.colorbar()
cb.set_label('log10(N)')
ax.set_xlabel (r'demod S/\(N\+I\)(dB) relative')
ax.set_ylabel (r'remod mse(dB) absolute')
plt.show()

_______________________________________________
Matplotlib-users mailing list
Matplotlib-users at python.org
Matplotlib-users Info Page

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/matplotlib-users/attachments/20160108/963e32bf/attachment.html&gt;