def dict_diff(dict1, dict2): """Return the difference between two dictionaries as a dictionary of key: [val1, val2] pairs. Keys unique to either dictionary are included as key: [val1, '-'] or key: ['-', val2].""" diff_keys = [] common_keys = pylab.intersect1d(dict1.keys(), dict2.keys()) for key in common_keys: if pylab.iterable(dict1[key]): if pylab.any(dict1[key] != dict2[key]): diff_keys.append(key) else: if dict1[key] != dict2[key]: diff_keys.append(key) dict1_unique = [key for key in dict1.keys() if key not in common_keys] dict2_unique = [key for key in dict2.keys() if key not in common_keys] diff = {} for key in diff_keys: diff[key] = [dict1[key], dict2[key]] for key in dict1_unique: diff[key] = [dict1[key], '-'] for key in dict2_unique: diff[key] = ['-', dict2[key]] return diff
def scatter_classic(x, y, s=None, c='b'): """ SCATTER_CLASSIC(x, y, s=None, c='b') Make a scatter plot of x versus y. s is a size (in data coords) and can be either a scalar or an array of the same length as x or y. c is a color and can be a single color format string or an length(x) array of intensities which will be mapped by the colormap jet. If size is None a default size will be used Copied from older version of matplotlib -- removed in version 0.9.1 for whatever reason. """ self = gca() if not self._hold: self.cla() if is_string_like(c): c = [c] * len(x) elif not iterable(c): c = [c] * len(x) else: norm = normalize() norm(c) c = cm.jet(c) if s is None: s = [abs(0.015 * (amax(y) - amin(y)))] * len(x) elif not iterable(s): s = [s] * len(x) if len(c) != len(x): raise ValueError, 'c and x are not equal lengths' if len(s) != len(x): raise ValueError, 's and x are not equal lengths' patches = [] for thisX, thisY, thisS, thisC in zip(x, y, s, c): circ = Circle( (thisX, thisY), radius=thisS, ) circ.set_facecolor(thisC) self.add_patch(circ) patches.append(circ) self.autoscale_view() return patches
def scatter_classic(x, y, s=None, c='b'): """ SCATTER_CLASSIC(x, y, s=None, c='b') Make a scatter plot of x versus y. s is a size (in data coords) and can be either a scalar or an array of the same length as x or y. c is a color and can be a single color format string or an length(x) array of intensities which will be mapped by the colormap jet. If size is None a default size will be used Copied from older version of matplotlib -- removed in version 0.9.1 for whatever reason. """ self = gca() if not self._hold: self.cla() if is_string_like(c): c = [c]*len(x) elif not iterable(c): c = [c]*len(x) else: norm = normalize() norm(c) c = cm.jet(c) if s is None: s = [abs(0.015*(amax(y)-amin(y)))]*len(x) elif not iterable(s): s = [s]*len(x) if len(c)!=len(x): raise ValueError, 'c and x are not equal lengths' if len(s)!=len(x): raise ValueError, 's and x are not equal lengths' patches = [] for thisX, thisY, thisS, thisC in zip(x,y,s,c): circ = Circle( (thisX, thisY), radius=thisS, ) circ.set_facecolor(thisC) self.add_patch(circ) patches.append(circ) self.autoscale_view() return patches
def __init__(self, data, x=[], y=[], tolerance=5, formatter=click): self._points = np.column_stack((x, y)) self.formatter = formatter if not p.iterable(data): data = [data] self.data = data self.axes = tuple(set(d.axes for d in self.data)) self.figures = tuple(set(ax.figure for ax in self.axes)) for d in self.data: d.set_picker(tolerance) for fig in self.figures: fig.canvas.mpl_connect('pick_event', self)
def norm_hist_bins(y, bins=10, normed='height'): """Just like the matplotlib mlab.hist, but can normalize by height. normed can be 'area' (produces matplotlib behavior, area is 1), any False value (no normalization), or any True value (normalization). Original docs from matplotlib: Return the histogram of y with bins equally sized bins. If bins is an array, use the bins. Return value is (n,x) where n is the count for each bin in x If normed is False, return the counts in the first element of the return tuple. If normed is True, return the probability density n/(len(y)*dbin) If y has rank>1, it will be raveled Credits: the Numeric 22 documentation """ y = asarray(y) if len(y.shape)>1: y = ravel(y) if not iterable(bins): ymin, ymax = min(y), max(y) if ymin==ymax: ymin -= 0.5 ymax += 0.5 if bins==1: bins=ymax dy = (ymax-ymin)/bins bins = ymin + dy*arange(bins) n = searchsorted(sort(y), bins) n = diff(concatenate([n, [len(y)]])) if normed: if normed == 'area': db = bins[1]-bins[0] else: db = 1.0 return 1/(len(y)*db)*n, bins else: return n, bins
weights2._edge2value[t][edge]) else: for edge in weights1._edge2value[t]: if t in weights2._edge2value and edge in weights2._edge2value[ t]: xs.append(weights1._edge2value[t][edge]) ys.append(weights2._edge2value[t][edge]) (min, max) = updateMinMax(min, max, weights1._edge2value[t][edge]) (min, max) = updateMinMax(min, max, weights2._edge2value[t][edge]) # plot print("data range: " + str(min) + " - " + str(max)) if options.verbose: print("Plotting...") if options.time_coloring and iterable(c): for i in range(0, len(c)): plot(xs[i], ys[i], '.', color=c[i], mfc=c[i]) else: plot(xs, ys, ',', color=c) # set axes if options.xticks != "": (xb, xe, xd, xs) = options.xticks.split(",") xticks(arange(xb, xe, xd), size=xs) if options.yticks != "": (yb, ye, yd, ys) = options.yticks.split(",") yticks(arange(yb, ye, yd), size=ys) if options.xlim != "": (xb, xe) = options.xlim.split(",") xlim(int(xb), int(xe)) else:
(min, max) = updateMinMax( min, max, weights2._edge2value[t][edge]) else: for edge in weights1._edge2value[t]: if t in weights2._edge2value and edge in weights2._edge2value[t]: xs.append(weights1._edge2value[t][edge]) ys.append(weights2._edge2value[t][edge]) (min, max) = updateMinMax( min, max, weights1._edge2value[t][edge]) (min, max) = updateMinMax( min, max, weights2._edge2value[t][edge]) # plot print("data range: " + str(min) + " - " + str(max)) if options.verbose: print("Plotting...") if options.time_coloring and iterable(c): for i in range(0, len(c)): plot(xs[i], ys[i], '.', color=c[i], mfc=c[i]) else: plot(xs, ys, ',', color=c) # set axes if options.xticks != "": (xb, xe, xd, xs) = options.xticks.split(",") xticks(arange(xb, xe, xd), size=xs) if options.yticks != "": (yb, ye, yd, ys) = options.yticks.split(",") yticks(arange(yb, ye, yd), size=ys) if options.xlim != "": (xb, xe) = options.xlim.split(",") xlim(int(xb), int(xe)) else: