python - 如何使用最小比例 python pygal

标签 python python-3.x python-2.7 pygal

所以我想要我的 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)

不用介意 User.query 的东西,因为 .date_created 返回一个日期时间。 无论如何,这个图返回这个 enter image description here

我希望 y 间隔先为 1,然后为 2,所以我不需要任何小数

最佳答案

您可以通过设置图表对象上的 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查看各种选项。

关于python - 如何使用最小比例 python pygal,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54611979/

相关文章:

python - 当我尝试通过multiprocess.Pool在python中加速程序时,为什么多进程比单进程慢?

python - 查找 float 中小数点后的数字总和,直到任意精度

python - 基于python中的子字符串匹配提取整个单词

python - 语音识别错误 Python

python - 在多对多字段中使用 through 属性并遇到 "Non-Unique"字段要求

python - 在 Pandas 中查找具有相同列值的数据框行

python - 为多个 Python 文件编写单元测试

python - Pandas 从值中删除第一个字符

python - 从 os.walk 中有效地删除 dirnames 中的子目录

python-2.7 - 如何让 iPython 使用 Python 2 而不是 Python 3