Line Plots

The Line plot method in Pygal generates a sequenced line plot with observations connected to each other over some x-index. Whether or not the index for $x$ values is provided, pygal will generate a y-based line plot. Whether a specific x-index is provided or not, Pygal automatically generates a y-based line plot. This feature often results in a cleaner appearance and provides a unique way to present line plots.

The examples below demonstrate how to generate lines plots with and without a corresponding $x$ indeces. The sunspots data is available here: https://public.websites.umich.edu/~mejn/computational-physics/sunspots.txt

import pygal
import numpy as np
import pandas as pd

sunspots = pd.read_csv('dataset/sunspots.txt', delimiter='\t', header=None)
sunspots.columns = ['month', 'sunspots']

sunspots.head()
month sunspots
0 0 58.0
1 1 62.6
2 2 70.0
3 3 55.7
4 4 85.0

Line Plot without an $x$ index

The code below generates a line plot using only the sunspots observations without the x-axis (months).

line_plot = pygal.Line()

line_plot.title = 'Sunspots Observations (1970 - 2000)'
line_plot.add('Sunspots', sunspots.sunspots[:30])

line_plot.render_in_browser()
Sunspots Observations (1970 - 2000) 50 50 60 60 70 70 80 80 90 90 100 100 110 110 120 120 130 130 140 140 150 150 Sunspots Observations (1970 - 2000) 58 12.36153846153846 459.0462139945198 62.6 33.674535809018565 438.52559647129584 70 54.98753315649867 405.51416828176167 55.7 76.30053050397878 469.30652275613176 85 97.61352785145887 338.599111140814 83.5 118.92652519893899 345.29061685490876 94.8 140.2395225464191 294.88127380872817 66.3 161.5525198938992 422.01988237652876 75.9 182.86551724137928 379.1942458063222 75.5 204.1785145888594 380.97864733008083 158.6 225.49151193633952 10.269230769230717 85.2 246.80450928381958 337.70691037893465 73.3 268.1175066312997 390.7928557107532 75.9 289.4305039787798 379.1942458063222 89.2 310.7435013262599 319.8628951413486 88.3 332.05649867374 323.8777985698055 90 353.36949602122013 316.2940920938314 100 374.6824933687002 271.6840539998663 85.4 395.99549071618037 336.8147096170553 103 417.30848806366043 258.30104257167676 91.2 438.62148541114055 310.9408875225556 65.7 459.9344827586207 424.69648466216665 63.3 481.24748010610074 435.4028938047183 75.4 502.56047745358086 381.4247477110205 70 523.873474801061 405.51416828176167 43.5 545.186472148541 523.7307692307693 45.3 566.4994694960211 515.7009623738555 56.4 587.8124668435013 466.1838200895542 60.7 609.1254641909815 447.00150370914923 50.7 630.4384615384615 491.61154180311433 Sunspots

Line Plot with $x$ index

The code below generates a line plot with the years as x index.

line_plot = pygal.Line( x_label_rotation = -35 )

line_plot.title = 'Subspots Observations (1970 - 2000)'
line_plot.x_labels = map(str, range(1970, 2000))
line_plot.add('Sunspots', sunspots.sunspots[:30])

#line_plot.render_in_browser()
Subspots Observations (1970 - 2000) 50 50 60 60 70 70 80 80 90 90 100 100 110 110 120 120 130 130 140 140 150 150 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 Subspots Observations (1970 - 2000) 58 12.36153846153846 438.6162208540943 1970 62.6 33.674535809018565 419.008879734108 1971 70 54.98753315649867 387.4666353236952 1972 55.7 76.30053050397878 448.4198914140875 1973 85 97.61352785145887 323.52965341069626 1974 83.5 118.92652519893899 329.92335160199616 1975 94.8 140.2395225464191 281.75749189420367 1976 66.3 161.5525198938992 403.2377575289016 1977 75.9 182.86551724137928 362.3180891045822 1978 75.5 204.1785145888594 364.0230752889289 1979 158.6 225.49151193633952 9.81219549091486 1980 85.2 246.80450928381958 322.67716031852297 1981 73.3 268.1175066312997 373.40049930283544 1982 75.9 289.4305039787798 362.3180891045822 1983 89.2 310.7435013262599 305.62729847505653 1984 88.3 332.05649867374 309.4635173898365 1985 90 353.36949602122013 302.2173261063633 1986 100 374.6824933687002 259.5926714976973 1987 85.4 395.99549071618037 321.82466722634956 1988 103 417.30848806366043 246.80527511509752 1989 91.2 438.62148541114055 297.10236755332335 1990 65.7 459.9344827586207 405.7952368054215 1991 63.3 481.24748010610074 416.0251539115014 1992 75.4 502.56047745358086 364.44932183501555 1993 70 523.873474801061 387.4666353236952 1994 43.5 545.186472148541 500.42197003665996 1995 45.3 566.4994694960211 492.7495322071001 1996 56.4 587.8124668435013 445.4361655914809 1997 60.7 609.1254641909815 427.10756410975455 1998 50.7 630.4384615384615 469.7322187184205 1999 Sunspots