コード例 #1
0
ファイル: matpos.py プロジェクト: Fumipo-Theta/matpos
    def add_grid(self,
                 sizes: List[Size],
                 column: int = 1,
                 margin: Union[Number, Size] = (0, 0),
                 **kwd) -> List[Subgrid]:
        """
        Generates subgrids aligning as grid layout.
        Order of subgrid is column prefered.

        Parameters
        ----------
        sizes: List[Tuple[float]]
            List of tuples which have 2 float numbers.
            The tuple defines width and height (w, h) of
                a subplot by unit of inches.

        column: int, optional
            Number of columns in grid.
            Default value is 1.

        offset: Tuple[float], optional
            Offsets between subgrids.
            It has 2 float numbers indicating horizontal and vertical
                distances (h, v) between subgrids.
            Default value is (0, 0).

        Return
        ------
        subgrids: List[Subgrid]
            List of instances of Subgrid class.
            The length is equal to that of sizes parameter.

        Example
        -------
        # Generate 3 x 3 grid from 9 subplots whose plot area sizes are 3 x 3.

        gridder = Gridder()

        subgrids = gridder.add_grid(
            [(3,3) for i in range(9)],
            3,
            offset=(0.5, 0.5)
        )

        """

        d = margin if type(margin) is tuple else (margin, margin)

        size, *rest_sizes = sizes
        a = self.from_left_top(self, size)

        def reducer(acc, e):
            l = len(acc)
            if l % column is 0:
                newSg = self.add_bottom(acc[l - column], e, d, **kwd)
            else:
                newSg = self.add_right(acc[l - 1], e, d, **kwd)
            return [*acc, newSg]

        return reducing(reducer)([a])(rest_sizes)
コード例 #2
0
ファイル: subplot.py プロジェクト: Fumipo-Theta/matdat
    def read(self, i) -> Tuple[pd.DataFrame]:
        """
        Indipendent from type of data source.
        """
        data: tuple = wrap_by_tuple(self.data[i])
        meta: tuple = wrap_by_tuple(self.dataInfo[i])
        default_transformers: tuple = self.default_transformers(i)
        data_transformers: tuple = wrap_by_tuple(self.dataTransformer[i])

        max_len = pip(it.mapping(len),
                      it.reducing(lambda acc, e: acc if acc > e else e)(0))([
                          data, meta, default_transformers, data_transformers
                      ])

        def get_with_duplicate(it, i, default=None):
            if len(it) is 0:
                return default
            return it[i] if len(it) > i else it[-1]

        dfs = []
        for j in range(max_len):
            d = get_with_duplicate(data, j, {})
            m = get_with_duplicate(meta, j, {})
            def_trans = get_with_duplicate(default_transformers, j, [])
            trans = get_with_duplicate(data_transformers, j, [])

            loader = ISubplot.IDataLoader(d, self.isTest())

            if self.isTest():
                transformers = None
            else:
                transformers = def_trans + trans

            dfs.append(loader.read(d, meta=m, transformers=transformers))
        return tuple(dfs)
コード例 #3
0
def to_flatlist(d: dict) -> List[dict]:
    """
    Usage
    -----
    d = {
        "x" : (0,1,2),
        "y" : [1,2],
        "z" : 0
    }

    to_flatlist(d) is...
    [
        {"x" : 0, "y" : [1,2], "z" : 0},
        {"x" : 1, "y" : [1,2], "z" : 0},
        {"x" : 2, "y" : [1,2], "z" : 0}
    ]

    """
    def value_to_list(d: dict) -> dict:
        return dict(
            it.mapping(lambda kv: (kv[0], kv[1]) if type(kv[1]) is tuple else
                       (kv[0], [kv[1]]))(d.items()))

    list_dict = value_to_list(d)

    max_length = it.reducing(lambda acc, e: acc if acc >= len(e) else len(e))(
        0)(list_dict.values())

    flatlist = []
    for i in range(max_length):
        new_dict = {}

        for k in list_dict.keys():
            if len(list_dict[k]) >= i + 1:
                new_dict.update({(k): list_dict[k][i]})
            else:
                new_dict.update({(k): list_dict[k][-1]})

        flatlist.append(new_dict)
    return flatlist
コード例 #4
0
        def set_data(data_source: DataSource,
                     option: dict = {},
                     **option_kwargs):
            """
            Parameters
            ----------
            df: pandas.DataFrame | dict
            option: dict, optional
                {
                    "x" : "x_name",
                    "y" : ["y1", "y2"],
                    "ylim" : (None,10),
                    "ylabel" : "Y",
                    "linewidth" : [1,1.5]
                }
            kwargs: parameters corresponding to items of option.
            """
            list_of_entry = to_flatlist({
                "data": data_source,
                **default_kwargs,
                **setting,
                **setting_kwargs,
                **option,
                **option_kwargs
            })
            # print(list_of_entry)

            arg_and_kwarg = generate_arg_and_kwags()(
                #as_DataFrame(data_source),
                #data_source,
                list(map(arg_filter, list_of_entry)),
                list(map(kwarg_filter, list_of_entry)))

            # return plot action
            return lambda ax: it.reducing(lambda acc, e: plotter(
                *e[0], **e[1])(acc))(ax)(arg_and_kwarg)
コード例 #5
0
ファイル: get_path.py プロジェクト: Fumipo-Theta/matdat
def isMatchAll(patterns):
    return lambda s: it.reducing(lambda a, b: a and b)(True)(it.mapping(
        lambda pattern: re.search(pattern, s) != None)(patterns))