Chart title settings

We are pretty familiar with chart titles from the past two chapters, but it is good to know that we can also give titles to the x and y axes. Take a look at the following code:

# -*- coding: utf-8 -*-
import pygal

param_line_chart = pygal.Line(interpolate='cubic', label_font_size=20, x_label_rotation=50)
param_line_chart.title = 'Parameter Line Chart'
param_line_chart.x_title='Data-Sets (X Axis)'
param_line_chart.y_title='Values (Y Axis)'

param_line_chart.x_labels = map(str, ["Data Object 1", "Data Object 2", "Data Object 3", "Data Object 4", "Data Object 5", "Data Object 6"])

param_line_chart.add('Data-Set 1', [8, 16, 24, 32, 48, 56])
param_line_chart.add('Data-Set 2', [2, 4, 6, 8, 10, 12])
param_line_chart.add('Data-Set 3', [1, 3, 5, 7, 9, 12])

param_line_chart.render_to_file('lineparam.svg')

The following screenshot shows the results of our script:

Chart title settings

We can adjust the font sizes for the x, y, and chart titles using the title_font_size, x_title_font_size, and y_title_font_size parameters, as shown in the following code:

# -*- coding: utf-8 -*-
import pygal

param_line_chart = pygal.Line(interpolate='cubic', label_font_size=20, x_label_rotation=50, title_font_size=24, x_title_font_size=24, y_title_font_size=24)
param_line_chart.title = 'Parameter Line Chart'
param_line_chart.x_title='Data-Sets (X Axis)'
param_line_chart.y_title='Values (Y Axis)'

param_line_chart.x_labels = map(str, ["Data Object 1", "Data Object 2", "Data Object 3", "Data Object 4", "Data Object 5", "Data Object 6"])

param_line_chart.add('Data-Set 1', [8, 16, 24, 32, 48, 56])
param_line_chart.add('Data-Set 2', [2, 4, 6, 8, 10, 12])
param_line_chart.add('Data-Set 3', [1, 3, 5, 7, 9, 12])

param_line_chart.render_to_file('lineparam.svg')

The following screenshot shows the results of our script:

Chart title settings
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.225.234.24