Now I have two sequences of data,
both have ten numbers in them called xvals here and yvals.
And then I'm going to call draw_line with the name "My Line Plot" and
the sequences of xvals and yvals.
So let's see what happens here.
Well, it rendered a line plot, and we can see the title, My line plot, and
then we can see my data.
Now something to notice here, notice what happened on the x-axis.
The numbers that I had in my xvals are evenly spaced, so
it doesn't interpret what's going on at all.
When I do a line plot in pygal,
all of the successive data items get plotted, evenly space.
And so you can see we have 0, 1, 3, 5, 6, and so on along the x-axis.
They're evenly spaced, there's a point at each location with a corresponding yval.
Now let's go back to the program, take a look at the program here.
I also have a function that I am calling draw_xy.
In the draw_xy function also takes a title, takes a sequence of x values and
the sequence of y values, and now I'm going to draw an xy scatter plot.
The difference between an xy plot is that I provide both the x value and
the y value of the coordinate as a tuple so
that pygal knows exactly where you want that point placed.
It does not assume that all of the values in the data should be
evenly spaced consecutively.
So at first I have to take that sequence of x values and y values, and
turn them into a sequence of tuples.
And to do this I'm going to use a list comprehension,
that list comprehension creates a tuple, xval, yval for
all the xval and yval values in, now what do we have here?
zip(xvals, yvals).
While I encourage you to read the documentation on zip, but effectively what
zip does is it takes multiple sequences and it zips them together, like a zipper.
So it takes the first element off of each of the sequences and
puts them in a tuple and returns that.
And then it takes the next element off each of the sequences,
puts them into tuple and returns that is the next value of the iteration.
So if I do that, I'm going to get a sequence of tuples where all the x
values and y values are put together and correlated.
So, you can see here, the xvals start with 0, 1, 3.
The yvals start with 4, 3, 1.
This will create tuple of 0, 4 then tuple 1, 3 then tuple 3, 1 and so on.