import numpy as np import pysal as ps import random as rdm from pysal.contrib.viz import mapping as maps shp_link = ps.examples.get_path('columbus.shp') shp = ps.open(shp_link) some = [bool(rdm.getrandbits(1)) for i in ps.open(shp_link)] fig = figure() base = maps.map_poly_shp(shp) base.set_facecolor('none') base.set_linewidth(0.75) base.set_edgecolor('0.8') some = maps.map_poly_shp(shp, which=some) some.set_alpha(0.5) some.set_linewidth(0.) cents = np.array([poly.centroid for poly in ps.open(shp_link)]) pts = scatter(cents[:, 0], cents[:, 1]) pts.set_color('red') ax = maps.setup_ax([base, some, pts]) fig.add_axes(ax) show() net_link = ps.examples.get_path('eberly_net.shp') net = ps.open(net_link) values = np.array(ps.open(net_link.replace('.shp', '.dbf')).by_col('TNODE')) pts_link = ps.examples.get_path('eberly_net_pts_onnetwork.shp') pts = ps.open(pts_link) fig = figure() netm = maps.map_line_shp(net) netc = maps.base_choropleth_unique(netm, values) ptsm = maps.map_point_shp(pts) ptsm = maps.base_choropleth_classif(ptsm, values) ptsm.set_alpha(0.5) ptsm.set_linewidth(0.) ax = maps.setup_ax([netc, ptsm]) fig.add_axes(ax) show() maps.plot_poly_lines(ps.examples.get_path('columbus.shp')) shp_link = ps.examples.get_path('columbus.shp') values = np.array(ps.open(ps.examples.get_path('columbus.dbf')).by_col('HOVAL')) types = ['classless', 'unique_values', 'quantiles', 'fisher_jenks', 'equal_interval'] for typ in types: maps.plot_choropleth(shp_link, values, typ, title=typ)