pygal

Documentation

Basic customizations

How to customize:

pygal is customized with the help of the Config class (see config.py). It can be changed in several ways:

By instanciating it

Just import the Config class and instanciate it:

from pygal import Config

config = Config()
config.show_legend = False
config.human_readable = True
config.fill = True
config.x_scale = .25
config.y_scale = .25
chart = pygal.XY(config)
...
By inheriting it

Import the Config class and override it:

from pygal import Config

class StarConfig(Config):
    show_legend = False
    human_readable = True
    fill = True
    x_scale = .25
    y_scale = .25

chart = pygal.XY(StarConfig())
...
Using keyword args

As a shorthand for a one shot config, you can specify all config arguments as keyword args:

chart = pygal.XY(show_legend=False, human_readable=True, fill=True, x_scale=.25, y_scale=.25)
...

Size

width, height, explicit_size

The simplest and usefull customizations is the svg size to render. It indicates the desired size of the svg.

chart = pygal.Bar(width=200, height=100)
chart.add('1', 1)
chart.add('2', 2)

You can also set explicit_size to True to add size attributes to the svg tag.

Scaling

include_x_axis

Scales are computed automaticaly between the min and the max values.

You may want to always have the absissa in your graph:

chart = pygal.Line(include_x_axis=True)
chart.add('line', [.0002, .0005, .00035])

range

You may also want to explicitly set a range, range takes a tuple containing min and max:

chart = pygal.Line(range=(.0001, .001))
chart.add('line', [.0002, .0005, .00035])

order_min

Finaly you can tell at which precision pygal should stop scaling (in log10):

chart = pygal.Line(order_min=-4)
chart.add('line', [.0002, .0005, .00035])

Title

title

You can add a title to the chart by setting the title option:

chart = pygal.Line(title=u'Some points')
chart.add('line', [.0002, .0005, .00035])

Two y axes

secondary

You can plot your values to 2 separate axes, thanks to wiktorn

chart = pygal.Line(title=u'Some different points')
chart.add('line', [.0002, .0005, .00035])
chart.add('other line', [1000, 2000, 7000], secondary=True)

Labels

Add labels

x_labels, y_labels

You can specify x labels and y labels, depending on the graph type:

chart = pygal.Line()
chart.x_labels = 'Red', 'Blue', 'Green'
chart.y_labels = .0001, .0003, .0004, .00045, .0005
chart.add('line', [.0002, .0005, .00035])
Rotate labels

x_label_rotation, y_label_rotation

Allow label rotation (in degrees) to avoid axis cluttering:

chart = pygal.Line()
chart.x_labels = ['This is the first point !', 'This is the second point !', 'This is the third point !', 'This is the fourth point !']
chart.add('line', [0, .0002, .0005, .00035])
chart = pygal.Line(x_label_rotation=20)
chart.x_labels = ['This is the first point !', 'This is the second point !', 'This is the third point !', 'This is the fourth point !']
chart.add('line', [0, .0002, .0005, .00035])
Change minor/major labels

x_labels_major, x_labels_major_every, x_labels_major_count, show_minor_x_labels

You can alter major minor behaviour for the abscissa thanks to Arjen Stolk

chart = pygal.Line(x_label_rotation=20)
chart.x_labels = ['This is the first point !', 'This is the second point !', 'This is the third point !', 'This is the fourth point !']
chart.x_labels_major = ['This is the first point !', 'This is the fourth point !']
chart.add('line', [0, .0002, .0005, .00035])
chart = pygal.Line(x_label_rotation=20, x_labels_major_every=3)
chart.x_labels = ['This is the first point !', 'This is the second point !', 'This is the third point !', 'This is the fourth point !']
chart.add('line', [0, .0002, .0005, .00035])
chart = pygal.Line(x_label_rotation=20, x_labels_major_count=3)
chart.x_labels = ['This is the first point !', 'This is the second point !', 'This is the third point !', 'This is the fourth point !']
chart.add('line', [0, .0002, .0005, .00035])
chart = pygal.Line(x_label_rotation=20, show_minor_x_labels=False)
chart.x_labels = ['This is the first point !', 'This is the second point !', 'This is the third point !', 'This is the fourth point !']
chart.x_labels_major = ['This is the first point !', 'This is the fourth point !']
chart.add('line', [0, .0002, .0005, .00035])

Display

show_legend, show dots

You can remove legend and dots by setting these at False

chart = pygal.Line(show_legend=False)
chart.add('line', [.0002, .0005, .00035])
chart = pygal.Line(show_dots=False)
chart.add('line', [.0002, .0005, .00035])

Legend at bottom

legend_at_bottom

You can put legend at bottom by setting legend_at_bottom at True:

chart = pygal.Line(legend_at_bottom=True)
chart.add('line', [.0002, .0005, .00035])

Rendering

fill, stroke, zero

You can disable line stroking:

chart = pygal.Line(stroke=False)
chart.add('line', [.0002, .0005, .00035])

And enable line filling:

chart = pygal.Line(fill=True)
chart.add('line', [.0002, .0005, .00035])

To fill to an other reference than zero:

chart = pygal.Line(fill=True, zero=.0004)
chart.add('line', [.0002, .0005, .00035])

Font sizes

label_font_size, value_font_size, tooltip_font_size, title_font_size, legend_font_size

Set the various font size

chart = pygal.Line(label_font_size=34, legend_font_size=8)
chart.add('line', [0, .0002, .0005, .00035])

Text truncation

truncate_legend, truncate_label

By default long text are automatically truncated at reasonable length which fit in the graph.

You can override that by setting truncation lenght with truncate_legend and truncate_label.

chart = pygal.Line(truncate_legend=3, truncate_label=17)
chart.x_labels = ['This is the first point !', 'This is the second point !', 'This is the third point !', 'This is the fourth point !']
chart.add('line', [0, .0002, .0005, .00035])

Human readable

human_readable

Display values in human readable form:

1 230 000 -> 1.23M .00 098 7 -> 987ยต

chart = pygal.Line(human_readable=True, y_scale=.0001)
chart.add('line', [0, .0002, .0005, .00035])

No data text

no_data_text

Text to display instead of the graph when no data is supplied:

chart = pygal.Line()
chart.add('line', [])
chart = pygal.Line(no_data_text='No result found')
chart.add('line', [])