Kivy:如何格式化x轴刻度标签?

时间:2018-03-15 10:41:30

标签: python time graph kivy labels

我正在使用纪录时间为我的x轴绘制实时图表,但是你可以从这个截图中看到

这不完全是人类可读的。绿线是当前活动,红线代表历史。我的图表的数据每秒从其他地方输入,只要值介于0到100之间,您就可以绘制任何您想要的内容(除非您更改yminymax

class CPUGraph(Graph):
    """Graph to show CPU data over time"""

    def __init__(self, **kwargs):
        super(CPUGraph, self).__init__(**kwargs)

        self.start_time = int(time.time())
        self.window_res = 300  # In seconds
        self.xlabel= "Time"
        self.ylabel = "CPU Usage (%)"
        self.y_ticks_major = 10
        self.y_grid_label = True
        self.x_grid_label = True
        self.x_grid = True
        self.y_grid = True
        self.padding = 10
        self.xmin = self.start_time
        self.xmax = self.start_time + self.window_res
        self.x_ticks_major = self.window_res/10
        self.ymin = 0
        self.ymax = 100
        self.tick_color = 1, 1, 1, 1
        self.background_color = 0.35, 0.35, 0.35, 1
        self.draw_border = False
        self.label_options = {'color': [1, 1, 1, 1]}

        self.data = []

       self.cpu_usage = LinePlot(color=[1, 0.1, 0.1, 0.85], line_width=2)
       self.current_usage = LinePlot(color=[0, 1, 0, 1], line_width=2)

       self.add_plot(self.current_usage)
       self.add_plot(self.cpu_usage)

   def update_plot(self, data_point):
       """Update plot with list of currently collected data"""

        if len(self.data) > (self.window_res * 0.95):
            self.xmax += 1
            self.xmin += 1

        self.data.append(data_point)
        self.cpu_usage.points = [((x + self.start_time), y) for x, y in enumerate(self.data)]
        self.current_usage.points = [(x, data_point) for x in range(self.xmin, self.xmax + 1)]

0 个答案:

没有答案
相关问题