def volume_unit_scroll(anchor, *colors): clear_strip() strip_center = strip.numPixels() / 2 meter_length = strip.numPixels() if anchor == 's' else strip_center color_map = ([Color(0, 0, 0)] * len(colors)) + color.get_color_map( len(colors) * 10, list(colors)) strip_pixels = np.zeros((strip.numPixels(), ), dtype=int) while (visual_flag == 3 and anchor == 's') or (visual_flag == 4 and anchor == 'c'): cur_data = np.fromstring(config.data, np.int16) peak = np.average(np.abs(cur_data) / 2) for i in range(strip.numPixels() - 1, 0, -1): if anchor == 's' or i >= strip_center: strip_pixels[i] = strip_pixels[i - 1] strip.setPixelColor(i, strip_pixels[i]) elif i > 0: strip_pixels[strip_center - i - 1] = strip_pixels[strip_center - i] strip.setPixelColor(strip_center - i - 1, strip_pixels[strip_center - i - 1]) cur_color = color_map[int( np.interp(peak, [0, 13000], [0, len(color_map)]))] if meter_length == strip.numPixels(): strip_pixels[0] = cur_color strip.setPixelColor(0, strip_pixels[0]) else: strip_pixels[strip_center] = cur_color strip_pixels[strip_center - 1] = cur_color strip.setPixelColor(strip_center, strip_pixels[strip_center]) strip.setPixelColor(strip_center - 1, strip_pixels[strip_center - 1]) strip.show() time.sleep(refresh_rate / 10)
def volume_unit_meter(anchor, *colors): clear_strip() strip_center = strip.numPixels() / 2 meter_length = strip.numPixels() if anchor == 's' else strip_center color_map = color.get_color_map(meter_length, list(colors)) prev_num_bars = 0 while (visual_flag == 1 and anchor == 's') or (visual_flag == 2 and anchor == 'c'): cur_data = np.fromstring(config.data, np.int16) peak = np.average(np.abs(cur_data) / 2) num_bars = int(np.interp(peak, [0, 13000], [0, meter_length])) if num_bars <= prev_num_bars: for i in range(prev_num_bars - 1, num_bars - 1, -1): if anchor == 's': strip.setPixelColor(i, Color(0, 0, 0)) else: strip.setPixelColor(i + strip_center, Color(0, 0, 0)) strip.setPixelColor(strip_center - i - 1, Color(0, 0, 0)) strip.show() time.sleep(refresh_rate / (prev_num_bars - num_bars)) else: for i in range(prev_num_bars, num_bars): if anchor == 's': strip.setPixelColor(i, color_map[i]) else: strip.setPixelColor(i + strip_center, color_map[i]) strip.setPixelColor(strip_center - i - 1, color_map[i]) strip.show() time.sleep(refresh_rate / (num_bars - prev_num_bars)) prev_num_bars = num_bars
def geoplot(db, col=None, palette='BuGn', classi='Quantiles', backend='mpl', color=None, facecolor='#4D4D4D', edgecolor='#B3B3B3', alpha=1., linewidth=0.2, marker='o', marker_size=20, ax=None, hover=True, p=None, tips=None, figsize=(9, 9), **kwargs): ''' Higher level plotter for geotables ... Parameters ---------- db : DataFrame GeoTable with 'geometry' column and values to be plotted. col : None/str [Optional. Default=None] Column holding the values to encode into the choropleth. palette : str/palettable palette String of the `palettable.colorbrewer` portfolio, or a `palettable` palette to use classi : str [Optional. Default='mpl'] Backend to plot the backend : str [Optional. Default='mpl'] Backend to plot the geometries. Available options include Matplotlib ('mpl') or Bokeh ('bk'). color : str/tuple/Series [Optional. Default=None] Wrapper that sets both `facecolor` and `edgecolor` at the same time. If set, `facecolor` and `edgecolor` are ignored. It allows for either a single color or a Series of the same length as `gc` with colors, indexed on `gc.index`. facecolor : str/tuple/Series [Optional. Default='#4D4D4D'] Color for polygons and points. It allows for either a single color or a Series of the same length as `gc` with colors, indexed on `gc.index`. edgecolor : str/tuple/Series [Optional. Default='#B3B3B3'] Color for the polygon and point edges. It allows for either a single color or a Series of the same length as `gc` with colors, indexed on `gc.index`. alpha : float/Series [Optional. Default=1.] Transparency. It allows for either a single value or a Series of the same length as `gc` with colors, indexed on `gc.index`. linewidth : float/Series [Optional. Default=0.2] Width(s) of the lines in polygon and line plotting (not applicable to points). It allows for either a single value or a Series of the same length as `gc` with colors, indexed on `gc.index`. marker : str [Optional. `mpl` backend only. Default='o'] Marker for point plotting. marker_size : int/Series [Optional. Default=0.15] Width(s) of the lines in polygon and ax : AxesSubplot [Optional. `mpl` backend only. Default=None] Pre-existing axes to which append the geometries. hover : Boolean [Optional. `bk` backend only. Default=True] Include hover tool. p : bokeh.plotting.figure [Optional. `bk` backend only. Default=None] Pre-existing bokeh figure to which append the collections and setup. tips : list of strings series names to add to hover tool kwargs : Dict Additional named vaues to be passed to the classifier of choice. ''' if col: if hasattr(palette, 'number') and 'k' in kwargs: if kwargs['k'] > palette.number: raise ValueError( 'The number of classes requested is greater than ' 'the number of colors available in the palette.') lbl, c = value_classifier(db[col], scheme=classi, **kwargs) if type(palette) is not str: palette = get_color_map(palette=palette, k=c.k) else: palette = get_color_map(name=palette, k=c.k) facecolor = lbl.map({i: j for i, j in enumerate(palette)}) try: kwargs.pop('k') except KeyError: pass col = [(col, db[col])] if tips: col = col or [] for tip in tips: col.append((tip, db[tip])) if col or tips: col.append(('index', db.index.values)) col = collections.OrderedDict(col) # put mapped variable at the top if backend is 'mpl': plot_geocol_mpl(db['geometry'], facecolor=facecolor, ax=ax, color=color, edgecolor=edgecolor, alpha=alpha, linewidth=linewidth, marker=marker, marker_size=marker_size, figsize=figsize, **kwargs) elif backend is 'bk': plot_geocol_bk(db['geometry'], facecolor=facecolor, color=color, edgecolor=edgecolor, alpha=alpha, linewidth=linewidth, marker_size=marker_size, hover=hover, p=p, col=col, **kwargs) else: warn("Please choose an available backend") return None
def geoplot(db, col=None, palette='BuGn', classi='Quantiles', backend='mpl', color=None, facecolor='#4D4D4D', edgecolor='#B3B3B3', alpha=1., linewidth=0.2, marker='o', marker_size=20, ax=None, hover=True, p=None, tips=None, figsize=(9,9), **kwargs): ''' Higher level plotter for geotables ... Arguments --------- db : DataFrame GeoTable with 'geometry' column and values to be plotted. col : None/str [Optional. Default=None] Column holding the values to encode into the choropleth. palette : str/palettable palette String of the `palettable.colorbrewer` portfolio, or a `palettable` palette to use classi : str [Optional. Default='mpl'] Backend to plot the backend : str [Optional. Default='mpl'] Backend to plot the geometries. Available options include Matplotlib ('mpl') or Bokeh ('bk'). color : str/tuple/Series [Optional. Default=None] Wrapper that sets both `facecolor` and `edgecolor` at the same time. If set, `facecolor` and `edgecolor` are ignored. It allows for either a single color or a Series of the same length as `gc` with colors, indexed on `gc.index`. facecolor : str/tuple/Series [Optional. Default='#4D4D4D'] Color for polygons and points. It allows for either a single color or a Series of the same length as `gc` with colors, indexed on `gc.index`. edgecolor : str/tuple/Series [Optional. Default='#B3B3B3'] Color for the polygon and point edges. It allows for either a single color or a Series of the same length as `gc` with colors, indexed on `gc.index`. alpha : float/Series [Optional. Default=1.] Transparency. It allows for either a single value or a Series of the same length as `gc` with colors, indexed on `gc.index`. linewidth : float/Series [Optional. Default=0.2] Width(s) of the lines in polygon and line plotting (not applicable to points). It allows for either a single value or a Series of the same length as `gc` with colors, indexed on `gc.index`. marker : str [Optional. `mpl` backend only. Default='o'] Marker for point plotting. marker_size : int/Series [Optional. Default=0.15] Width(s) of the lines in polygon and ax : AxesSubplot [Optional. `mpl` backend only. Default=None] Pre-existing axes to which append the geometries. hover : Boolean [Optional. `bk` backend only. Default=True] Include hover tool. p : bokeh.plotting.figure [Optional. `bk` backend only. Default=None] Pre-existing bokeh figure to which append the collections and setup. tips : list of strings series names to add to hover tool kwargs : Dict Additional named vaues to be passed to the classifier of choice. ''' if col: if hasattr(palette, 'number') and 'k' in kwargs: if kwargs['k'] > palette.number: raise ValueError('The number of classes requested is greater than ' 'the number of colors available in the palette.') lbl,c = value_classifier(db[col], scheme=classi, **kwargs) if type(palette) is not str: palette = get_color_map(palette=palette, k=c.k) else: palette = get_color_map(name=palette, k=c.k) facecolor = lbl.map({i:j for i,j in enumerate(palette)}) try: kwargs.pop('k') except KeyError: pass col = [(col, db[col])] if tips: for tip in tips: col.append((tip, db[tip])) col.append(('index', db.index.values)) col = collections.OrderedDict(col) # put mapped variable at the top if backend is 'mpl': plot_geocol_mpl(db['geometry'], facecolor=facecolor, ax=ax, color=color, edgecolor=edgecolor, alpha=alpha, linewidth=linewidth, marker=marker, marker_size=marker_size, figsize=figsize, **kwargs) elif backend is 'bk': plot_geocol_bk(db['geometry'], facecolor=facecolor, color=color, edgecolor=edgecolor, alpha=alpha, linewidth=linewidth, marker_size=marker_size, hover=hover, p=p, col=col, **kwargs) else: warn("Please choose an available backend") return None