pythonpython-3.xpython-2.7pygal

How to use min scale python pygal


So i want integer intervals between my y axis variables in my pygal graph. Here is my code:

    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)

nevermind the User.query stuff since the .date_created returns a datetime. Anyway this graph returns this enter image description here

I want the y intervals to say 1 and then 2, so I dont want any decimals


Solution

  • You can specify the position of y ticks by setting the y_labels attribute on the chart object.

    For example:

    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]
    

    Which generates the following chart:

    Pygal line chart with custom y ticks

    Refer to the docs to see the various options.