All right. In this lecture, you'll learn
how to make time series graphs. So we're
talking about data where one of the
axis, so normally the x axis consists of
dates or times. So let's say we have
temperature observations for several
dates, we're going to have to pull these
values along the x and y axis. I've got
some nice data here.
[No audio]
Let's
[No audio]
we're going to take from this link. So it's a CSV file.
[No audio]
You don't have to download the
CSV file actually, because we will be
passing it as a link directly to the
CSV method. So what we've got here is
a Date column and some other attributes.
So you may want to plot the Date along
the x axis and then in the y axis, you
want to show one of these features.
Let's say this attribute Close. So I'm
going to close this, I don't need this
file, because I'll use a direct link.
And let me create a new cell. So I'll be
using again, the bokeh. plotting
interface here. And also import pandas.
The key here is, we will be using a
pandas dataframe and then we will
parse this date datetime column as dates
so that Python reads them as dates, and
actually is able to plot them in the x
axis. And then we'll be using a line
glyph to plot this data. So a line glyph
would be, you know, you can use circles,
triangles, etc. But you can also use
lines. So you'd pass line here. But then
the size doesn't make sense, because you
may want to pass a line_width for the
line, so not size but line_width. And if
you execute this, you don't see circles
anymore. So it's not a scatterplot. Now,
but it's a line chart. So we will
use the same concept for building this
datetime graph, timeseries graph.
So first thing you want to do is load the
CSV data inside Python. So pandas.read_csv,
and you can pass actually the link
this link directly to the CSV method.
[No audio]
So how convenient is that. And then you
want to pass the parse_dates parameter
here, and you want to specify the name
of the column where these dates are. And
the name of that column was Date. So if
you remember from the CSV file that I
opened earlier, that was Date. So once
you load the dataframe object, you want
to create a figure object. Let's say
width equals to 500.
[No audio]
And height, let's say 500 for now, then we
check how it goes and we can change it later. So
we have the x_axis_type parameter here. So
what we should do is, you only want to
make your axis your x axis spatial. So
let it carry datetime datatypes.
So to declare that you have datetimes,
you need to pass a datatime argument as a
string there. So that's it. Then what
you want to do is apply the line object
in there. So similar to this, now you
need to pass the x axis and the y axis.
So the x axis here should be df Date.
And the other axis is, let's say Close.
So the Close column. Let's make the line Orange.
And what else, maybe a transparency alpha 0.5.
[Author typing]
And specify where you want to save this.
So on the what name HTML, Timeseries.html.
And lastly, show the plot, and let's see.
And something is not working. So Python
is not being able to pull all the data there.
[No audio]
Yeah, I need to parse the date here as a list actually.
[No audio]
So
[No audio]
yeah. Now it looks better. But it also looks a
bit squeezed. So what you can do here is,
you can change this to, let's say, 250.
[No audio]
And you'll get a better graph there. Now, if
you want to extend it to the entire page, there's
something you can do there. You can
actually pass the responsive and set it to True.
[No audio]
Let's see.
[No audio]
So you have you get a bigger graph there.
Of course, you can zoom in to see some details there.
So for May 8, I have a value of 180, you'll get the idea.
[No audio]
So that's concludes this lecture.
And I'll see you in the next one.