def kde(data, bins=None, kernel=None, **kwargs): """ kde(a, bins=None, range=None, **kwargs) Make a kernerl density estimate plot of the data. This is like a histogram, but produces a smoother result, thereby better represening the probability density function. See the vv.StatData for more statistics on data. Parameters ---------- a : array_like The data to calculate the historgam of. bins : int (optional) The number of bins. If not given, the best number of bins is determined automatically using the Freedman-Diaconis rule. kernel : float or sequence (optional) The kernel to use for distributing the values. If a scalar is given, a Gaussian kernel with a sigma equal to the given number is used. If not given, the best kernel is chosen baded on the number of bins. kwargs : keyword arguments These are given to the plot function. """ # Get stats from visvis.processing.statistics import StatData stats = StatData(data) # Get kde xx, values = stats.kde(bins, kernel) # Plot return vv.plot(xx, values, **kwargs)
box.SetWhiskers(value) return locals() if __name__ == '__main__': vv.figure(1) vv.clf() a = vv.gca() d1 = np.random.normal(1, 4, (1000, 1000)) d2 = np.random.normal(2, 3, (20, )) d3 = np.random.uniform(-1, 3, (100, )) d4 = [ 1, 2, 1, 2.0, 8, 2, 3, 1, 2, 2, 3, 2, 2.1, 8, 8, 8, 8, 8, 1.2, 1.3, 0, 0, 1.5, 2 ] b = boxplot((d1, d2, d3, d4), width=0.8, whiskers='violin') ## dd = d4 stat = StatData(dd) bins1, values1 = stat.histogram_np(normed=True) bins2, values2 = stat.histogram() bins3, values3 = stat.kde() vv.figure(2) vv.clf() vv.bar(bins2, values2) #, lc='r', ms='.', mc='r') vv.plot(bins3, values3) #, lc='g', ms='.', mc='g') vv.plot(bins1, values1, lc='b', ms='.', mc='b', ls=':', mw=4) #print abs(bins1-bins2).sum()
""" Get/Set the style of the whiskers. """ def fget(self): return self._boxes[0]._whiskers def fset(self, value): for box in self._boxes: box.SetWhiskers(value) return locals() if __name__ == '__main__': vv.figure(1); vv.clf() a = vv.gca() d1 = np.random.normal(1, 4, (1000,1000)) d2 = np.random.normal(2, 3, (20,)) d3 = np.random.uniform(-1, 3, (100,)) d4 = [1,2,1,2.0, 8, 2, 3, 1, 2, 2, 3, 2, 2.1, 8, 8, 8, 8, 8, 1.2, 1.3, 0, 0, 1.5, 2] b = boxplot((d1,d2,d3, d4), width=0.8, whiskers='violin') ## dd = d4 stat = StatData(dd) bins1, values1 = stat.histogram_np(normed=True) bins2, values2 = stat.histogram() bins3, values3 = stat.kde( ) vv.figure(2); vv.clf() vv.bar(bins2, values2)#, lc='r', ms='.', mc='r') vv.plot(bins3, values3)#, lc='g', ms='.', mc='g') vv.plot(bins1, values1, lc='b', ms='.', mc='b', ls=':', mw=4) #print abs(bins1-bins2).sum()