def hist(data, bins=None, drange=None, normed=False, weights=None): """ hist(a, bins=None, range=None, normed=False, weights=None) Make a histogram plot of the data. Uses np.histogram (new version) internally. See its docs for more information. See the kde() function for a more accurate density estimate. See the vv.StatData for more statistics on data. Parameters ---------- a : array_like The data to calculate the historgam of. bins : int or sequence of scalars, optional If `bins` is an int, it defines the number of equal-width bins in the given range. If `bins` is a sequence, it defines the bin edges, including the rightmost edge, allowing for non-uniform bin widths. If bins is not given, the best number of bins is determined automatically using the Freedman-Diaconis rule. range : (float, float) The lower and upper range of the bins. If not provided, range is simply (a.min(), a.max()). Values outside the range are ignored. normed : bool If False, the result will contain the number of samples in each bin. If True, the result is the value of the probability *density* function at the bin, normalized such that the *integral* over the range is 1. Note that the sum of the histogram values will not be equal to 1 unless bins of unity width are chosen; it is not a probability *mass* function. weights : array_like An array of weights, of the same shape as `a`. Each value in `a` only contributes its associated weight towards the bin count (instead of 1). If `normed` is True, the weights are normalized, so that the integral of the density over the range remains 1. """ # Auto determine bins? if bins is None: from visvis.processing.statistics import StatData stats = StatData(data) bins = stats.best_number_of_bins() # let numpy do the work if np.__version__ < '1.3': values, edges = np.histogram(data, bins, drange, normed, weights, new=True) else: values, edges = np.histogram(data, bins, drange, normed, weights) # the bins are the left bin edges, let's get the centers centers = np.empty(values.shape, np.float64) for i in range(len(values)): centers[i] = (edges[i] + edges[i+1]) * 0.5 # plot dbin = centers[1] - centers[0] return vv.bar(centers, values, width=dbin*0.9)
def hist(data, bins=None, drange=None, normed=False, weights=None): """ hist(a, bins=None, range=None, normed=False, weights=None) Make a histogram plot of the data. Uses np.histogram (new version) internally. See its docs for more information. See the kde() function for a more accurate density estimate. See the vv.StatData for more statistics on data. Parameters ---------- a : array_like The data to calculate the historgam of. bins : int or sequence of scalars, optional If `bins` is an int, it defines the number of equal-width bins in the given range. If `bins` is a sequence, it defines the bin edges, including the rightmost edge, allowing for non-uniform bin widths. If bins is not given, the best number of bins is determined automatically using the Freedman-Diaconis rule. range : (float, float) The lower and upper range of the bins. If not provided, range is simply (a.min(), a.max()). Values outside the range are ignored. normed : bool If False, the result will contain the number of samples in each bin. If True, the result is the value of the probability *density* function at the bin, normalized such that the *integral* over the range is 1. Note that the sum of the histogram values will not be equal to 1 unless bins of unity width are chosen; it is not a probability *mass* function. weights : array_like An array of weights, of the same shape as `a`. Each value in `a` only contributes its associated weight towards the bin count (instead of 1). If `normed` is True, the weights are normalized, so that the integral of the density over the range remains 1. """ # Auto determine bins? if bins is None: from visvis.processing.statistics import StatData stats = StatData(data) bins = stats.best_number_of_bins() # let numpy do the work values, edges = np.histogram(data, bins, drange, normed, weights) # the bins are the left bin edges, let's get the centers centers = np.empty(values.shape, np.float64) for i in range(len(values)): centers[i] = (edges[i] + edges[i + 1]) * 0.5 # plot dbin = centers[1] - centers[0] return vv.bar(centers, values, width=dbin * 0.9)
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()
if self._colors: return self._colors[0] else: return None def fset(self, value): c = vv.misc.getColor(value) self._colors = [c for h in self._hh] return locals() @vv.misc.PropWithDraw def colors(): """ Get/Set the colors of all bars at once. The number of colors should match the number of bars. """ def fget(self): return [c for c in self._colors] def fset(self, value): if len(value) != len(self._colors): raise ValueError( 'Number of colors should match number of bars.') getColor = vv.misc.getColor self._colors = [getColor(c) for c in value] return locals() if __name__ == '__main__': b = vv.bar([1, 2, 1, 5])
def color(): """ Get/Set the color of the bars. The getter returns the color of the first bar, or None if there are no bars. """ def fget(self): if self._colors: return self._colors[0] else: return None def fset(self, value): c = vv.misc.getColor(value) self._colors = [c for h in self._hh] return locals() @vv.misc.PropWithDraw def colors(): """ Get/Set the colors of all bars at once. The number of colors should match the number of bars. """ def fget(self): return [c for c in self._colors] def fset(self, value): if len(value) != len(self._colors): raise ValueError('Number of colors should match number of bars.') getColor = vv.misc.getColor self._colors = [getColor(c) for c in value] return locals() if __name__ == '__main__': b = vv.bar([1,2,1,5])
if ":" not in line: continue temps = [float(t) for t in line.split(': ')[1].split(' ')] for i in range(12): temps_per_month[i].append(temps[i]) # Calculate means mean = lambda x: sum(x)/len(x) mean_temps_per_month = [mean(tt) for tt in temps_per_month] # Prepare figure vv.figure(1); vv.clf() # Show means in a normal bar chart a1 = vv.subplot(221); b2 = vv.bar(mean_temps_per_month) b2.color = 'r' # Show means in a 3D bar chart a2 = vv.subplot(222); b3 = vv.bar3(mean_temps_per_month) b3.color = 'g' a2.daspect = 1,1,0.3 # Show box plot a3 = vv.subplot(223) bp = vv.boxplot(temps_per_month) bp.lc = 'b' bp.lw = 2 # Show violin plot
continue temps = [float(t) for t in line.split(': ')[1].split(' ')] for i in range(12): temps_per_month[i].append(temps[i]) # Calculate means mean = lambda x: sum(x) / len(x) mean_temps_per_month = [mean(tt) for tt in temps_per_month] # Prepare figure vv.figure(1) vv.clf() # Show means in a normal bar chart a1 = vv.subplot(221) b2 = vv.bar(mean_temps_per_month) b2.color = 'r' # Show means in a 3D bar chart a2 = vv.subplot(222) b3 = vv.bar3(mean_temps_per_month) b3.color = 'g' a2.daspect = 1, 1, 0.3 # Show box plot a3 = vv.subplot(223) bp = vv.boxplot(temps_per_month) bp.lc = 'b' bp.lw = 2 # Show violin plot