def plot_regions(regions, bbox, tag): """Output one shapefile for each region (represented by its bottom left and upper right index in the grid) with color depending of its discrepancy.""" # TODO not unicode safe discrepancies = [v[0] for v in regions] colormap = cm.ScalarMappable( mcolor.Normalize(min(discrepancies), max(discrepancies)), 'YlOrBr') schema = {'geometry': 'Polygon', 'properties': {}} style = [] KARTO_CONFIG['bounds']['data'] = [BBOX[1], BBOX[0], BBOX[3], BBOX[2]] polys = [{'geometry': mapping(r[1]), 'properties': {}} for r in regions] for i, r in enumerate(regions): color = to_css_hex(colormap.to_rgba(r[0])) name = u'disc_{}_{:03}'.format(tag, i + 1) KARTO_CONFIG['layers'][name] = {'src': name + '.shp'} color = 'red' style.append(CSS.format(name, color, 'black')) # style.append(CSS.format(name, color, color)) with fiona.collection(mkpath('disc', name + '.shp'), "w", "ESRI Shapefile", schema) as f: f.writerecords(polys) break with open(mkpath('disc', 'photos.json'), 'w') as f: json.dump(KARTO_CONFIG, f) with open(mkpath('disc', 'photos.css'), 'w') as f: f.write('\n'.join(style))
def tag_cloud(words, coords, label): from matplotlib.font_manager import FontProperties import matplotlib import matplotlib.cm as cm import matplotlib.colors as colors matplotlib.use('PDF') import matplotlib.pyplot as plt plt.figure(dpi=200) H = read_entropy() colormap_ = cm.ScalarMappable( colors.Normalize(min(H.values()), max(H.values())), 'Blues') font0 = FontProperties() pos = {'horizontalalignment': 'center', 'verticalalignment': 'center'} font0.set_size(1.4) for w, c in zip(words, coords): plt.plot(c[0], c[1], '.', ms=5, c=to_css_hex(colormap_.to_rgba(H[w]))) if label: plt.text(c[0], c[1], w, fontproperties=font0, rotation=randint(-28, 28), **pos) plt.axis('off') plt.savefig('red.pdf', format='pdf', transparent=True)
def plot_regions(regions, bbox, tag): """Output one shapefile for each region (represented by its bottom left and upper right index in the grid) with color depending of its discrepancy.""" # TODO not unicode safe discrepancies = [v[0] for v in regions] colormap = cm.ScalarMappable(mcolor.Normalize(min(discrepancies), max(discrepancies)), 'YlOrBr') schema = {'geometry': 'Polygon', 'properties': {}} style = [] KARTO_CONFIG['bounds']['data'] = [BBOX[1], BBOX[0], BBOX[3], BBOX[2]] polys = [{'geometry': mapping(r[1]), 'properties': {}} for r in regions] for i, r in enumerate(regions): color = to_css_hex(colormap.to_rgba(r[0])) name = u'disc_{}_{:03}'.format(tag, i+1) KARTO_CONFIG['layers'][name] = {'src': name+'.shp'} color = 'red' style.append(CSS.format(name, color, 'black')) # style.append(CSS.format(name, color, color)) with fiona.collection(mkpath('disc', name+'.shp'), "w", "ESRI Shapefile", schema) as f: f.writerecords(polys) break with open(mkpath('disc', 'photos.json'), 'w') as f: json.dump(KARTO_CONFIG, f) with open(mkpath('disc', 'photos.css'), 'w') as f: f.write('\n'.join(style))
def plot_polygons(bucket, tag, nb_inter, minv, maxv): schema = {'geometry': 'Polygon', 'properties': {}} colormap_ = matplotlib.cm.ScalarMappable(cmap='YlOrBr') vrange = np.linspace(minv, maxv, nb_inter) colormap = [to_css_hex(c) for c in colormap_.to_rgba(vrange)] style = [] for i in range(nb_inter): if len(bucket[i]) > 0: name = u'{}_freq_{:03}'.format(tag, i + 1) KARTO_CONFIG['layers'][name] = {'src': name + '.shp'} style.append(CSS.format(name, colormap[i], colormap[i])) with fiona.collection(name + '.shp', "w", "ESRI Shapefile", schema) as f: f.writerecords(bucket[i]) with open('photos.json', 'w') as f: json.dump(KARTO_CONFIG, f) with open('photos.css', 'w') as f: f.write('\n'.join(style))
def plot_polygons(bucket, tag, nb_inter, minv, maxv): schema = {'geometry': 'Polygon', 'properties': {}} colormap_ = matplotlib.cm.ScalarMappable(cmap='YlOrBr') vrange = np.linspace(minv, maxv, nb_inter) colormap = [to_css_hex(c) for c in colormap_.to_rgba(vrange)] style = [] for i in range(nb_inter): if len(bucket[i]) > 0: name = u'{}_freq_{:03}'.format(tag, i+1) KARTO_CONFIG['layers'][name] = {'src': name+'.shp'} style.append(CSS.format(name, colormap[i], colormap[i])) with fiona.collection(name+'.shp', "w", "ESRI Shapefile", schema) as f: f.writerecords(bucket[i]) with open('photos.json', 'w') as f: json.dump(KARTO_CONFIG, f) with open('photos.css', 'w') as f: f.write('\n'.join(style))
def tag_cloud(words, coords, label): from matplotlib.font_manager import FontProperties import matplotlib import matplotlib.cm as cm import matplotlib.colors as colors matplotlib.use("PDF") import matplotlib.pyplot as plt plt.figure(dpi=200) H = read_entropy() colormap_ = cm.ScalarMappable(colors.Normalize(min(H.values()), max(H.values())), "Blues") font0 = FontProperties() pos = {"horizontalalignment": "center", "verticalalignment": "center"} font0.set_size(1.4) for w, c in zip(words, coords): plt.plot(c[0], c[1], ".", ms=5, c=to_css_hex(colormap_.to_rgba(H[w]))) if label: plt.text(c[0], c[1], w, fontproperties=font0, rotation=randint(-28, 28), **pos) plt.axis("off") plt.savefig("red.pdf", format="pdf", transparent=True)