如何使用min scale python pygal

问题描述 投票:1回答:1

所以我希望我的pygal图中的y轴变量之间有整数区间。这是我的代码:

    graph = pygal.Line(min_scale=1,x_label_rotation=35, truncate_label=-1, no_data_text="", style=custom_style, width=1000, height=400, explicit_size=True)
    x_labels = []
    data = []
    for i in range(1,len(User.query.all())+1):
        data.append(i)
        x_labels.append(User.query.filter_by(id=i).first().date_created)
    graph.x_labels = x_labels
    graph.add("Count", data)

因为.date_created返回一个日期时间,所以没关注User.query的东西。无论如何,此图表返回此enter image description here

我希望y间隔说1然后2,所以我不想要任何小数

python python-3.x python-2.7 pygal
1个回答
1
投票

您可以通过在图表对象上设置y_labels属性来指定y刻度的位置。

例如:

graph = pygal.Line(min_scale=1, width=400, height=300)
graph.add("Count", [1, 1.5, 2])
graph.x_labels = ["A", "B", "C"]
graph.y_labels = [1, 2]

这会生成以下图表:

Pygal line chart with custom y ticks

请参阅docs以查看各种选项。

© www.soinside.com 2019 - 2024. All rights reserved.