示例#1
0
def draw_pref_regions(dist, max_card, cmap):
    pts = jp.pref_points(jp.get_data())
    c = cmap(list(map(lambda c: c / max_card, dist)))
    for i in range(47):
        poly = plt.Polygon(pts[i], ec='k', fc=c[i], lw=0.5)
        plt.gca().add_patch(poly)
    plt.autoscale()
示例#2
0
def pref_map1(ips,
              cols=None,
              texts=None,
              width=1,
              qpqo=None,
              rough=False,
              tostr=False,
              ratio=(0.812, -1)):
    """ベクトルデータ(SVG)"""
    from IPython.display import SVG
    assert all(1 <= ip <= 47 for ip in ips), 'Must be 1 <= ip <= 47'
    if cols is None:
        cols = 'red fuchsia purple navy blue teal aqua green ' \
               'lime olive yellow orange orangered maroon'.split()
    elif isinstance(cols, str) and cols == 'gray':
        cols = [
            '#%02x%02x%02x' % ((i * 18 + 32, ) * 3)
            for i in [1, 8, 5, 10, 3, 0, 4, 7, 2, 9, 6]
        ]
    if texts is None:
        texts = [''] * len(ips)
    pnts = jp.pref_points(qpqo, rough)
    pp = [[[i[0] * ratio[0], i[1] * ratio[1]] for i in pnts[ip - 1]]
          for ip in ips]
    ppp = np.array(sum(pp, []))
    mx, mn = np.nanmax(ppp, 0), np.nanmin(ppp, 0)
    mx = max(mx - mn)
    s = ''.join(
        '<path fill="none" stroke="gray" stroke-width="0.001" d="%s"/>' %
        ('M' + ' '.join(['L%g,%g' % (x, y)
                         for x, y in (p - mn) / mx])[1:] + ' Z')
        for i, p in enumerate(pp))
    c = list((np.mean([(x, y) for x, y in (p - mn) / mx], axis=0)
              for i, p in enumerate(pp)))
    t = ''.join('<text x="%g" y="%g" text-anchor="middle">%s</text>' %
                (c[i][0], c[i][1], texts[i]) for i in range(len(ips))
                if texts[i] != '')
    s = '<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="400" height="400" viewBox="0 0 %d 1" style="font-family:sans-serif; font-size:0.04">%s%s</svg>' % (
        width, s, t)
    return s if tostr else SVG(s)
示例#3
0
文件: a2.py 项目: satemochi/saaaaah
def get_pts():
    with open('japan.p2.pkl', 'rw') as f:
        return jp.pref_points(pickle.load(f))
示例#4
0
        while len(qs) > t and cross3(qs[-1], qs[-2], p) > 0:
            qs.pop()
        qs.append(p)
    return qs


def calc_area(ps):
    ret = 0.0
    for (x0, y0), (x1, y1) in zip(ps, ps[1:]):
        ret += x0 * y1 - x1 * y0
    ret *= 0.5
    return ret


qpqo = japanmap.get_data()
pnts = japanmap.pref_points(qpqo)

# We don't have to care for presice scalling
lat0 = pnts[20][0][1] * DEG2RAD
lon0 = pnts[20][0][0] * DEG2RAD

ranking = []
for i in range(47):
    x = []
    y = []
    enus = []
    for lon, lat in pnts[i]:
        lat *= DEG2RAD
        lon *= DEG2RAD
        e, n, u = pymap3d.geodetic2enu(lat, lon, 0.0, lat0, lon0, 0.0)
        # values have to be distinct