> """ > First attempt at a histogram strip chart (made up name). > if-main block taken from [1] except that I've replaced uniform distributions > with normal distributions. > [1] > http://matplotlib.sourceforge.net/examples/pylab_examples/boxplot_demo3.html > """ > import numpy as np > import matplotlib.pyplot as plt > from matplotlib import collections > > NORM_TYPES = dict(max=max, sum=sum) > class BinCollection(collections.PatchCollection): > def __init__(self, hist, bin_edges, x=0, width=1, cmap=plt.cm.gray_r, > norm_type='max', **kwargs): > yy = (bin_edges[:-1] + bin_edges[1:])/2. > heights = np.diff(bin_edges) > bins = [plt.Rectangle((x, y), width, h) for y, h in zip(yy, heights)] > norm = NORM_TYPES[norm_type] > fc = cmap(np.asarray(hist, dtype=float)/norm(hist))
> super(BinCollection, self).__init__(bins, facecolors=fc, **kwargs) Is this equivalent to writing collections.PatchCollection.__init__() and what are the advantages of super()? I think you can use axes.pcolor() to replace BinCollection. pcolor() just adds a collection similar to what you do now by hand for you. With appropriate arguments it should do the job. You can also look into pcolorfast() and pcolormesh(). > def histstrip(x, positions=None, widths=None, ax=None): > if ax is None: > ax = plt.gca() > if positions is None: > positions = range(1, len(x) + 1) > if widths is None: > widths = np.min(np.diff(positions)) / 2. * np.ones(len(positions)) > for data, x_pos, w in zip(x, positions, widths): > x_pos -= w/2. > hist, bin_edges = np.histogram(data) No other arguments to numpy.histogram() allowed? > bins = BinCollection(hist, bin_edges, width=w, x=x_pos) > ax.add_collection(bins, autolim=True) > ax.set_xticks(positions) > ax.autoscale_view() > if __name__ == '__main__': > import matplotlib.pyplot as plt > import numpy as np > np.random.seed(2) > inc = 0.1 > e1 = np.random.normal(0,1, size=(500,)) > e2 = np.random.normal(0,1, size=(500,)) > e3 = np.random.normal(0,1 + inc, size=(500,)) > e4 = np.random.normal(0,1 + 2*inc, size=(500,)) > treatments = [e1,e2,e3,e4] > fig, ax = plt.subplots() > pos = np.array(range(len(treatments)))+1 > histstrip(treatments, ax=ax) > ax.set_xlabel('treatment') > ax.set_ylabel('response') > fig.subplots_adjust(right=0.99,top=0.99) > plt.show() In my opinion this is too special to be added as a general matplotlib plotting feature. Friedrich ------------------------------------------------------------------------------ Virtualization is moving to the mainstream and overtaking non-virtualized environment for deploying applications. Does it make network security easier or more difficult to achieve? Read this whitepaper to separate the two and get a better understanding. http://p.sf.net/sfu/hp-phase2-d2d _______________________________________________ Matplotlib-users mailing list Matplotlib-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/matplotlib-users