예제 #1
0
def colorRamp(num_points, colorRamp, code):
    colorTable = pd.read_csv("color/color.csv")
    idx_df = colorTable.set_index(["NAME"])
    [startColor, endColor] = ms.parseStr(colorRamp, "-")
    rgb_start = [int(idx_df.loc[startColor, "R"]),
                 int(idx_df.loc[startColor, "G"]),
                 int(idx_df.loc[startColor, "B"])]
    rgb_end = [int(idx_df.loc[endColor, "R"]),
               int(idx_df.loc[endColor, "G"]),
               int(idx_df.loc[endColor, "B"])]
    # [R_list, G_list, B_list]
    rgb_list = [ar.interp(s, e, num_points)
                for (s, e) in zip(rgb_start, rgb_end)]
    if code == "hex":
        hex_list = []
        for i in range(num_points):
            r = rgb_list[0][i]
            g = rgb_list[1][i]
            b = rgb_list[2][i]
            string = rgb2hex(r, g, b)
            hex_list.append(string)
        return hex_list
    elif code == "rgb":
        color_list = []
        for i in range(num_points):
            r = int(rgb_list[0][i])
            g = int(rgb_list[1][i])
            b = int(rgb_list[2][i])
            color_list.append([r, g, b])
        return color_list
예제 #2
0
def breakpt(data, num_category, method, wtnumpy):
    minimaxi = od.findMinMax(data)
    mini = minimaxi[0]
    maxi = minimaxi[1]
    # equal distance of data between max and min
    if (method == "even"):
        breakpoints = ar.interp(mini, maxi, num_category + 1)
    # same number of data per group
    elif (method == "quantile"):
        interval = 1.0 / num_category * 100.0
        # if you have the numpy package
        if wtnumpy:
            breakpoints = [np.percentile(data, interval * x)
                           for x in range(num_category)] + [maxi + 1]
        else:
            interval = 1.0 / num_category
            breakpoints = [percentile(sorted(data), interval * x)
                           for x in range(num_category)] + [maxi + 1]
    # implement later
    elif (method == "Jenks"):
        print("not implemented yet!")
        # psudo code: Calculate the sum of squared deviations between
        # classes (SDBC).  Calculate the sum of squared deviations
        # from the array mean (SDAM).  Subtract the SDBC from the SDAM
        # (SDAM-SDBC). This equals the sum of the squared deviations
        # from the class means (SDCM).  After inspecting each of the
        # SDBC, a decision is made to move one unit from the class
        # with the largest SDBC toward the class with the lowest SDBC.
    return breakpoints
예제 #3
0
def colorInterp(num_points, rgb_start, rgb_end):
    rgb_list = [ar.interp(s, e, num_points)
                for (s, e) in zip(rgb_start, rgb_end)]
    return [[rgb_list[0][i], rgb_list[1][i], rgb_list[2][i]] for i in
            range(num_points)]