Plotting time series data using pandas
The pandas library offers built-in plotting capabilities for visualizing data stored in a DataFrame or Series data structure. In the backend, these visualizations are powered by the Matplotlib library, which is also the default option.
The pandas library offers many convenient methods to plot data. Simply calling DataFrame.plot()
or Series.plot()
will generate a line plot by default. You can change the type of the plot in two ways:
- Using the
.plot(kind="<sometype>")
parameter to specify the type of plot by replacing<sometype>
with a chart type. For example,.plot(kind="hist")
will plot a histogram while.plot(kind="bar")
will produce a bar plot. - Alternatively, you can extend
.plot()
. This can be achieved by chaining a specific plot function, such as.hist()
or.scatter()
, for example, using.plot.hist()
or.plot.line()
.
This recipe will use the standard pandas .plot()
method with...