def test(self): w = util.Color(255, 255, 255, 255) b = util.Color(0, 0, 0, 255) op = numeric.BinarySegment(b, w, 5) aggs = np.array([[0, 0, 0, 0, 0], [1, 1, 1, 1, 1], [5, 5, 5, 5, 5], [6, 6, 6, 6, 6], [9, 9, 9, 9, 9], [0, 1, 5, 6, -1]]) out = op.shade(aggs) expected = np.array([[b, b, b, b, b], [b, b, b, b, b], [w, w, w, w, w], [w, w, w, w, w], [w, w, w, w, w], [b, b, w, w, b]]) self.assertTrue(np.array_equal(out, expected))
def __init__(self, cutoff, cat=0, above=util.Color(228, 26, 28, 255), below=util.Color(55, 126, 184, 255), background=util.Color(255, 255, 255, 0)): self.cutoff = cutoff self.cat = cat self.above = np.array(above, dtype=np.uint8) self.below = np.array(below, dtype=np.uint8) self.background = np.array(background, dtype=np.uint8)
def test_linear(self): red = util.Color(255, 0, 0, 255) white = util.Color(255, 255, 255, 255) op = numeric.InterpolateColors(white, red) aggs = np.arange(0, 256).reshape((32, 8)) out = op.shade(aggs) var = np.arange(0, 256)[::-1].reshape((32, 8)) const = np.empty((32, 8), dtype=np.int) const.fill(255) expected = np.dstack((const, var, var, const)) self.assertTrue(np.array_equal(out, expected))
def __init__(self, colors, background=util.Color(255, 255, 255, 255), alphamin=0, log=False, logbase=10): """ colors -- a list of colors in cateogry-order. alphamin -- minimum alpha value when (default is 0) log -- Log-based interpolate? (default is false) logbase -- Base to use if log is true (default is 10) background -- Color for empty category list (default is white) If C categories and N colors are presented: * N == C: No problems * N > C: Only the first C colors are used * N < C: The last color is replicated to make N == C TODO: Change 'colors' to a dictionary of category-to-color mapping TODO: mask out zero-sum regions in alpha and opaque blend """ self.catcolors = np.array( [np.array(v, dtype=np.uint8) for v in colors]) self.background = np.array(background, dtype=np.uint8) self.alphamin = alphamin self.log = log self.logbase = logbase
def __init__(self, low, high, log=False, reserve=util.Color(255, 255, 255, 255), empty=np.nan): self.low = low self.high = high self.reserve = reserve self.log = log self.empty = empty
def _create_plot_component(): red = util.Color(255, 0, 0, 255) green = util.Color(0, 255, 0, 255) blue = util.Color(0, 0, 255, 255) purple = util.Color(125, 0, 255, 255) white = util.Color(255, 255, 255, 255) black = util.Color(0, 0, 0, 255) clear = util.Color(0, 0, 0, 0) with Timer("Loeading") as arTimer: #glyphs = npg.load_csv("../data/circlepoints.csv", 1, 2, 3, 4) #glyphs = npg.load_hdf("../data/CensusTracts.hdf5", "__data__", "LAT", "LON") glyphs = npg.load_hdf("../data/tweets-subset.hdf", "test", "longitude", "latitude", vc="lang_primary") screen = (800, 600) ivt = util.zoom_fit(screen, glyphs.bounds()) with Timer("Abstract-Render") as arTimer: image = core.render( glyphs, infos.encode(["Arabic", "English", "Turkish", "Russian"]), npg.PointCountCategories(), npg.Spread(2) + categories.HDAlpha( [red, blue, green, purple, black], alphamin=.3, log=True), screen, ivt) # image = core.render(glyphs, # infos.valAt(4,0), # npg.PointCount(), # npg.Spread(1) + numeric.BinarySegment(white, black, 1), # screen, # ivt) # Create a plot data object and give it this data pd = ArrayPlotData() pd.set_data("imagedata", image) # Create the plot plot = Plot(pd) img_plot = plot.img_plot("imagedata")[0] # Tweak some of the plot properties plot.title = "Abstract Rendering" plot.padding = 50 return plot
def _create_plot_component(): red = util.Color(255, 0, 0, 255) green = util.Color(0, 255, 0, 255) blue = util.Color(0, 0, 255, 255) purple = util.Color(125, 0, 255, 255) white = util.Color(255, 255, 255, 255) black = util.Color(0, 0, 0, 255) shape = glyphset.ShapeCodes.RECT glyphs = blzg.load_csv( "../data/circlepoints.csv", "x", "y", "series", schema="{r:float32, theta:float32, x:float32, y:float32, series:int32}" ) screen = (800, 600) ivt = util.zoom_fit(screen, glyphs.bounds()) with Timer("Abstract-Render") as arTimer: image = core.render( glyphs, infos.val(), blzg.CountCategories("int32"), categories.HDAlpha([red, blue, green, purple, black]), screen, ivt) # image = core.render(glyphs, # infos.valAt(4,0), # blzg.Count(), # numeric.BinarySegment(white, black, 1), # screen, # ivt) # Create a plot data object and give it this data pd = ArrayPlotData() pd.set_data("imagedata", image) # Create the plot plot = Plot(pd) img_plot = plot.img_plot("imagedata")[0] # Tweak some of the plot properties plot.title = "Abstract Rendering" plot.padding = 50 return plot
def _test(self, r, g, b, a): c = util.Color(r, g, b, a) self.assertEqual(util.Color(r, g, b, a), c) self.assertEqual(c, [r, g, b, a])