当前位置: 首页>>代码示例>>Python>>正文


Python util.compute_scale函数代码示例

本文整理汇总了Python中pygal.util.compute_scale函数的典型用法代码示例。如果您正苦于以下问题:Python compute_scale函数的具体用法?Python compute_scale怎么用?Python compute_scale使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了compute_scale函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _compute

    def _compute(self):
        # Approximatively the same code as in XY.
        # The only difference is the transformation of dates to numbers
        # (beginning) and the reversed transformation to dates (end)
        self._offset = min([val[0]
                            for serie in self.series
                            for val in serie.values
                            if val[0] is not None]
                           or [datetime.datetime.fromtimestamp(0)])
        for serie in self.all_series:
            serie.values = [(self._tonumber(v[0]), v[1]) for v in serie.values]

        xvals = [val[0]
                 for serie in self.series
                 for val in serie.values
                 if val[0] is not None]
        yvals = [val[1]
                 for serie in self.series
                 for val in serie.values
                 if val[1] is not None]
        if xvals:
            xmin = min(xvals)
            xmax = max(xvals)
            rng = (xmax - xmin)
        else:
            rng = None

        for serie in self.all_series:
            serie.points = serie.values
            if self.interpolate and rng:
                vals = list(zip(*sorted(
                    [t for t in serie.points if None not in t],
                    key=lambda x: x[0])))
                serie.interpolated = self._interpolate(vals[0], vals[1])

        if self.interpolate and rng:
            xvals = [val[0]
                     for serie in self.all_series
                     for val in serie.interpolated]
            yvals = [val[1]
                     for serie in self.all_series
                     for val in serie.interpolated]
            if xvals:
                xmin = min(xvals)
                xmax = max(xvals)
                rng = (xmax - xmin)
            else:
                rng = None

        if rng:
            self._box.xmin, self._box.xmax = min(xvals), max(xvals)
            self._box.ymin, self._box.ymax = min(yvals), max(yvals)

        x_pos = compute_scale(
            self._box.xmin, self._box.xmax, self.logarithmic, self.order_min)
        y_pos = compute_scale(
            self._box.ymin, self._box.ymax, self.logarithmic, self.order_min)

        self._x_labels = list(zip(list(map(self._todate, x_pos)), x_pos))
        self._y_labels = list(zip(list(map(self._format, y_pos)), y_pos))
开发者ID:Qalthos,项目名称:pygal,代码行数:60,代码来源:datey.py

示例2: _compute

    def _compute(self):
        if self.xvals:
            xmin = min(self.xvals)
            xmax = max(self.xvals)
            xrng = (xmax - xmin)
        else:
            xrng = None

        if self.yvals:
            ymin = min(min(self.yvals), self.zero)
            ymax = max(max(self.yvals), self.zero)
            yrng = (ymax - ymin)
        else:
            yrng = None

        for serie in self.all_series:
            serie.points = serie.values

        if xrng:
            self._box.xmin, self._box.xmax = xmin, xmax
        if yrng:
            self._box.ymin, self._box.ymax = ymin, ymax

        x_pos = compute_scale(
            self._box.xmin, self._box.xmax, self.logarithmic, self.order_min)
        y_pos = compute_scale(
            self._box.ymin, self._box.ymax, self.logarithmic, self.order_min)

        self._x_labels = list(zip(map(self._format, x_pos), x_pos))
        self._y_labels = list(zip(map(self._format, y_pos), y_pos))
开发者ID:AlexSnet,项目名称:pygal,代码行数:30,代码来源:histogram.py

示例3: _compute

    def _compute(self):
        if self.xvals:
            xmin = min(self.xvals)
            xmax = max(self.xvals)
            xrng = (xmax - xmin)
        else:
            xrng = None

        if self.yvals:
            ymin = self._min
            ymax = self._max

            if self.include_x_axis:
                ymin = min(ymin or 0, 0)
                ymax = max(ymax or 0, 0)

            yrng = (ymax - ymin)
        else:
            yrng = None

        for serie in self.all_series:
            serie.points = serie.values
            if self.interpolate and xrng:
                vals = list(zip(*sorted(
                    filter(lambda t: None not in t,
                           serie.points), key=lambda x: x[0])))
                serie.interpolated = self._interpolate(vals[0], vals[1])

        if self.interpolate and xrng:
            self.xvals = [val[0]
                          for serie in self.all_series
                          for val in serie.interpolated]
            self.yvals = [val[1]
                          for serie in self.series
                          for val in serie.interpolated]
            if self.xvals:
                xmin = min(self.xvals)
                xmax = max(self.xvals)
                xrng = (xmax - xmin)
            else:
                xrng = None

        if xrng:
            self._box.xmin, self._box.xmax = xmin, xmax
        if yrng:
            self._box.ymin, self._box.ymax = ymin, ymax

        x_pos = compute_scale(
            self._box.xmin, self._box.xmax, self.logarithmic, self.order_min)
        y_pos = compute_scale(
            self._box.ymin, self._box.ymax, self.logarithmic, self.order_min)

        self._x_labels = list(zip(map(self._format, x_pos), x_pos))
        self._y_labels = list(zip(map(self._format, y_pos), y_pos))
开发者ID:AlexSnet,项目名称:pygal,代码行数:54,代码来源:xy.py

示例4: _compute

    def _compute(self):
        xvals = [val[0]
                 for serie in self.series
                 for val in serie.values
                 if val[0] is not None]
        yvals = [val[1]
                 for serie in self.series
                 for val in serie.values
                 if val[1] is not None]
        if xvals:
            xmin = min(xvals)
            xmax = max(xvals)
            rng = (xmax - xmin)
        else:
            rng = None

        for serie in self.series:
            serie.points = serie.values
            if self.interpolate and rng:
                vals = zip(*sorted(
                    filter(lambda t: None not in t,
                           serie.points), key=lambda x: x[0]))
                serie.interpolated = self._interpolate(
                    vals[1], vals[0], xy=True, xy_xmin=xmin, xy_rng=rng)

        if self.interpolate and rng:
            xvals = [val[0]
                     for serie in self.series
                     for val in serie.interpolated]
            yvals = [val[1]
                     for serie in self.series
                     for val in serie.interpolated]
            if xvals:
                xmin = min(xvals)
                xmax = max(xvals)
                rng = (xmax - xmin)
            else:
                rng = None

        if rng:
            self._box.xmin, self._box.xmax = min(xvals), max(xvals)
            self._box.ymin, self._box.ymax = min(yvals), max(yvals)

        x_pos = compute_scale(
            self._box.xmin, self._box.xmax, self.logarithmic, self.order_min)
        y_pos = compute_scale(
            self._box.ymin, self._box.ymax, self.logarithmic, self.order_min)

        self._x_labels = zip(map(self._format, x_pos), x_pos)
        self._y_labels = zip(map(self._format, y_pos), y_pos)
开发者ID:NicholasShatokhin,项目名称:spindl,代码行数:50,代码来源:xy.py

示例5: _compute

    def _compute(self):
        """
        This method was taken from Pygal.XY class, with my minor changes. It's
        licensed under GPL v3 or greater.
        """
        for serie in self.series:
            for metadata in serie.metadata:
                if not hasattr(metadata.value, '__iter__'):
                    metadata.value = (metadata.value, self.zero)

        xvals = [val[0]
                 for serie in self.series
                 for val in serie.values
                 if val[0] is not None]
        yvals = [val[1]
                 for serie in self.series
                 for val in serie.values
                 if val[1] is not None]
        xmin = min(xvals)
        xmax = max(xvals)
        rng = (xmax - xmin)

        for serie in self.series:
            serie.points = serie.values
            if self.interpolate:
                vals = zip(*sorted(serie.points, key=lambda x: x[0]))
                serie.interpolated = self._interpolate(
                    vals[1], vals[0], xy=True, xy_xmin=xmin, xy_rng=rng)
                if not serie.interpolated:
                    serie.interpolated = serie.values

        if self.interpolate:
            xvals = [val[0]
                     for serie in self.series
                     for val in serie.interpolated]
            yvals = [val[1]
                     for serie in self.series
                     for val in serie.interpolated]

        self._box.xmin, self._box.xmax = min(xvals), max(xvals)
        self._box.ymin, self._box.ymax = min(yvals), max(yvals)
        x_pos = compute_scale(self._box.xmin, self._box.xmax, self.logarithmic,
            self.order_min)
        y_pos = compute_scale(self._box.ymin, self._box.ymax, self.logarithmic,
            self.order_min)

        self._x_labels = zip(map(self._format_x, x_pos), x_pos)
        self._y_labels = zip(map(self._format, y_pos), y_pos)
开发者ID:pbanaszkiewicz,项目名称:django-collectd-webdaemon,代码行数:48,代码来源:utils.py

示例6: _compute

    def _compute(self):
        transposed = zip(*[serie.values for serie in self.series])
        positive_vals = [sum([
            val if val is not None and val > self.zero else self.zero
            for val in vals]) - self.zero
            for vals in transposed]
        negative_vals = [sum([
            val - self.zero
            if val is not None and val < self.zero else self.zero
            for val in vals]) + self.zero
            for vals in transposed]

        self._box.ymin, self._box.ymax = (
            min(min(negative_vals), self.zero),
            max(max(positive_vals), self.zero))

        x_pos = [
            x / self._len for x in range(self._len + 1)
        ] if self._len > 1 else [0, 1]  # Center if only one value
        y_pos = compute_scale(
            self._box.ymin, self._box.ymax, self.logarithmic, self.order_min
        ) if not self.y_labels else map(float, self.y_labels)
        self._x_ranges = zip(x_pos, x_pos[1:])

        self._x_labels = self.x_labels and zip(self.x_labels, [
            sum(x_range) / 2 for x_range in self._x_ranges])
        self._y_labels = zip(map(self._format, y_pos), y_pos)
开发者ID:rayleyva,项目名称:pygal,代码行数:27,代码来源:stackedbar.py

示例7: _compute

    def _compute(self):
        x_pos = [x / (self._len - 1) for x in range(self._len)
        ] if self._len != 1 else [.5]  # Center if only one value

        for serie in self.series:
            if not hasattr(serie, 'points'):
                serie.points = [
                    (x_pos[i], v)
                    for i, v in enumerate(serie.values)]
                if self.interpolate:
                    serie.interpolated = self._interpolate(serie.values, x_pos)

        if self.include_x_axis:
            self._box.ymin = min(self._min, 0)
            self._box.ymax = max(self._max, 0)
        else:
            self._box.ymin = self._min
            self._box.ymax = self._max

        y_pos = compute_scale(
            self._box.ymin, self._box.ymax, self.logarithmic, self.order_min
        ) if not self.y_labels else map(float, self.y_labels)

        self._x_labels = self.x_labels and zip(self.x_labels, x_pos)
        self._y_labels = zip(map(self._format, y_pos), y_pos)
开发者ID:rjmcguire,项目名称:pygal,代码行数:25,代码来源:line.py

示例8: _compute

    def _compute(self):
        xlen = len(self.series)
        x_pos = [(x + 1) / xlen for x in range(xlen)
        ] if xlen != 1 else [.5]  # Center if only one value

        previous = [[0, 0] for i in range(self._len)]
        for i, serie in enumerate(self.series):
            y_height = - sum(serie.values) / 2
            all_x_pos = [0] + x_pos
            serie.points = []
            for j, value in enumerate(serie.values):
                poly = []
                poly.append((all_x_pos[i], previous[j][0]))
                poly.append((all_x_pos[i], previous[j][1]))
                previous[j][0] = y_height
                y_height = previous[j][1] = y_height + value
                poly.append((all_x_pos[i + 1], previous[j][1]))
                poly.append((all_x_pos[i + 1], previous[j][0]))
                serie.points.append(poly)

        val_max = max(map(sum, cut(self.series, 'values')))
        self._box.ymin = -val_max
        self._box.ymax = val_max

        y_pos = compute_scale(
            self._box.ymin, self._box.ymax, self.logarithmic, self.order_min
        ) if not self.y_labels else map(float, self.y_labels)

        self._x_labels = zip(cut(self.series, 'title'),
                             map(lambda x: x - 1 / (2 * xlen), x_pos))
        self._y_labels = zip(map(self._format, y_pos), y_pos)
开发者ID:rjmcguire,项目名称:pygal,代码行数:31,代码来源:funnel.py

示例9: _compute

    def _compute(self):
        x_pos = [x / (self._len - 1) for x in range(self._len)] if self._len != 1 else [0.5]  # Center if only one value

        self._points(x_pos)

        if self.include_x_axis:
            self._box.ymin = min(self._min, 0)
            self._box.ymax = max(self._max, 0)
        else:
            self._box.ymin = self._min
            self._box.ymax = self._max

        y_pos = (
            compute_scale(self._box.ymin, self._box.ymax, self.logarithmic, self.order_min)
            if not self.y_labels
            else map(float, self.y_labels)
        )

        x_labels = zip(self.x_labels, x_pos)

        if self.x_labels_num_limit and len(x_labels) > self.x_labels_num_limit:
            step = (len(x_labels) - 1) / (self.x_labels_num_limit - 1)
            x_labels = list(x_labels[int(i * step)] for i in range(self.x_labels_num_limit))

        self._x_labels = self.x_labels and x_labels
        self._y_labels = zip(map(self._format, y_pos), y_pos)
开发者ID:wiktorn,项目名称:pygal,代码行数:26,代码来源:line.py

示例10: _compute

    def _compute(self):
        delta = 2 * pi / self._len if self._len else 0
        x_pos = [0.5 * pi + i * delta for i in range(self._len + 1)]
        for serie in self.series:
            serie.points = [(v, x_pos[i]) for i, v in enumerate(serie.values)]
            if self.interpolate:
                extend = 2
                extended_x_pos = (
                    [0.5 * pi + i * delta for i in range(-extend, 0)]
                    + x_pos
                    + [0.5 * pi + i * delta for i in range(self._len + 1, self._len + 1 + extend)]
                )
                extended_vals = serie.values[-extend:] + serie.values + serie.values[:extend]
                serie.interpolated = self._interpolate(extended_vals, extended_x_pos, polar=True)

        # x labels space
        self._box.margin *= 2
        self._rmin = self.zero
        self._rmax = self._max or 1
        self._box.set_polar_box(self._rmin, self._rmax)

        y_pos = (
            compute_scale(self._rmin, self._rmax, self.logarithmic, self.order_min, max_scale=8)
            if not self.y_labels
            else list(map(int, self.y_labels))
        )

        self._x_labels = self.x_labels and list(zip(self.x_labels, x_pos))
        self._y_labels = list(zip(list(map(self._format, y_pos)), y_pos))

        self.x_pos = x_pos
        self._self_close = True
开发者ID:nutztherookie,项目名称:pygal,代码行数:32,代码来源:radar.py

示例11: _compute

    def _compute(self):
        x_pos = [
            (x + 1) / self._order for x in range(self._order)
        ] if self._order != 1 else [.5]  # Center if only one value

        previous = [[self.zero, self.zero] for i in range(self._len)]
        for i, serie in enumerate(self.series):
            y_height = - sum(serie.safe_values) / 2
            all_x_pos = [0] + x_pos
            serie.points = []
            for j, value in enumerate(serie.values):
                poly = []
                poly.append((all_x_pos[i], previous[j][0]))
                poly.append((all_x_pos[i], previous[j][1]))
                previous[j][0] = y_height
                y_height = previous[j][1] = y_height + value
                poly.append((all_x_pos[i + 1], previous[j][1]))
                poly.append((all_x_pos[i + 1], previous[j][0]))
                serie.points.append(poly)

        val_max = max(list(map(sum, cut(self.series, 'values'))) + [self.zero])
        self._box.ymin = -val_max
        self._box.ymax = val_max

        y_pos = compute_scale(
            self._box.ymin, self._box.ymax, self.logarithmic, self.order_min,
            self.min_scale, self.max_scale
        ) if not self.y_labels else list(map(float, self.y_labels))

        self._x_labels = list(
            zip(cut(self.series, 'title'),
                map(lambda x: x - 1 / (2 * self._order), x_pos)))
        self._y_labels = list(zip(map(self._format, y_pos), y_pos))
开发者ID:langelee,项目名称:pygal,代码行数:33,代码来源:funnel.py

示例12: _compute_y_labels

 def _compute_y_labels(self):
     y_pos = compute_scale(
         self.min_, self.max_, self.logarithmic,
         self.order_min, self.min_scale, self.max_scale
     )
     if self.y_labels:
         self._y_labels = []
         for i, y_label in enumerate(self.y_labels):
             if isinstance(y_label, dict):
                 pos = self._adapt(y_label.get('value'))
                 title = y_label.get('label', self._y_format(pos))
             elif is_str(y_label):
                 pos = self._adapt(y_pos[i])
                 title = y_label
             else:
                 pos = self._adapt(y_label)
                 title = self._y_format(pos)
             self._y_labels.append((title, pos))
         self.min_ = min(self.min_, min(cut(self._y_labels, 1)))
         self.max_ = max(self.max_, max(cut(self._y_labels, 1)))
         self._box.set_polar_box(
             0, 1,
             self.min_,
             self.max_)
     else:
         self._y_labels = list(zip(map(self._y_format, y_pos), y_pos))
开发者ID:aroraumang,项目名称:pygal,代码行数:26,代码来源:gauge.py

示例13: _compute

    def _compute(self):
        # X Labels
        x_pos = [
            x / (self._len - 1) for x in range(self._len)
        ] if self._len != 1 else [.5]  # Center if only one value

        self._points(x_pos)

        if self.x_labels:
            label_len = len(self.x_labels)
            if label_len != self._len:
                label_pos = [0.5] if label_len == 1 else [
                    x / (label_len - 1) for x in range(label_len)
                ]
                self._x_labels = list(zip(self.x_labels, label_pos))
            else:
                self._x_labels = list(zip(self.x_labels, x_pos))
        else:
            self._x_labels = None

        if self.include_x_axis:
        # Y Label
            self._box.ymin = min(self._min or 0, 0)
            self._box.ymax = max(self._max or 0, 0)
        else:
            self._box.ymin = self._min
            self._box.ymax = self._max

        y_pos = compute_scale(
            self._box.ymin, self._box.ymax, self.logarithmic, self.order_min
        ) if not self.y_labels else list(map(float, self.y_labels))

        self._y_labels = list(zip(map(self._format, y_pos), y_pos))
开发者ID:philt2001,项目名称:pygal,代码行数:33,代码来源:line.py

示例14: _compute

    def _compute(self):
        positive_vals = zip(*[serie.safe_values
                              for index, serie in enumerate(self.series)
                              if index % 2])
        negative_vals = zip(*[serie.safe_values
                              for index, serie in enumerate(self.series)
                              if not index % 2])
        positive_sum = map(sum, positive_vals) or [0]
        negative_sum = map(sum, negative_vals) or [0]

        self._box.ymax = max(max(positive_sum), max(negative_sum))
        self._box.ymin = - self._box.ymax

        x_pos = [
            x / self._len
            for x in range(self._len + 1)
        ] if self._len > 1 else [0, 1]  # Center if only one value
        y_pos = compute_scale(
            self._box.ymin, self._box.ymax, self.logarithmic, self.order_min
        ) if not self.y_labels else map(float, self.y_labels)

        self._x_ranges = zip(x_pos, x_pos[1:])

        self._x_labels = self.x_labels and zip(self.x_labels, [
            sum(x_range) / 2 for x_range in self._x_ranges])
        self._y_labels = zip(map(self._format, y_pos), y_pos)
开发者ID:Zanarh,项目名称:pygal,代码行数:26,代码来源:verticalpyramid.py

示例15: _compute

    def _compute(self):
        ymin = self.y_label_min if self.y_label_min is not None else self._min
        ymax = self.y_label_max if self.y_label_max is not None else self._max
        
        if ymin:
            self._box.ymin = min(ymin, self.zero)
        if ymax:
            self._box.ymax = max(ymax, self.zero)

        x_pos = [
            x / self._len for x in range(self._len + 1)
        ] if self._len > 1 else [0, 1]  # Center if only one value

        self._points(x_pos)
        
        y_pos = compute_scale(
            self._box.ymin, self._box.ymax, self.logarithmic, self.order_min
        ) if not self.y_labels else map(float, self.y_labels)
        
        if self.y_labels_descriptions:
            y_pos.extend([key for key in self.y_labels_descriptions.keys() if key >= self._box.ymin and key <= self._box.ymax])
            y_pos.sort()

        self._x_labels = self.x_labels and zip(self.x_labels, [
            (i + .5) / self._len for i in range(self._len)])
        format = functools.partial(self._describe_label, self._format)
        self._y_labels = zip(map(format, y_pos), y_pos)
开发者ID:ebolwidt,项目名称:pygal,代码行数:27,代码来源:bar.py


注:本文中的pygal.util.compute_scale函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。