Welcome aboard to another insightful flight of analysis! Today, we will venture across the clouded skies of data visualization using line plots. We aim to transform numerical data from our Seaborn Flights dataset into these plots that can guide us through time and trends.
Now, you might wonder why visualization is needed when we already traversed the flights dataset in our prior lessons? Through visualization, we can unearth underlying patterns, visualize massive volumes of data, track changes over time, and compare variables. This ability to visualize data is a widely sought-after skill in diverse fields, including data analytics, business intelligence, and data science.
Observing the number of passengers traveling each month over the years yields crucial insights: Is there a season attracting more travelers? How has the number of passengers evolved over the years? To answer these intriguing questions, let's board this data visualization expression!
Matplotlib, a multi-platform data visualization library built on NumPy arrays, offers a wide range of graphical displays. It is designed for creating professional and high-quality graphics by fine-tuning every imaginable element of a graph. Here, we primarily use the pyplot module for 2D plotting with Matplotlib.
Enough with the chit-chat! Let's get our hands dirty with some visualization.
This simple block of code imports Matplotlib's pyplot module, the Seaborn library, and loads the 'flights' dataset from Seaborn's readily available datasets collection using the load_dataset() function. Once loaded, the data is available as a dataframe, which we'd use for our analysis.
The Flights dataset provides the number of passengers for each month from 1949 to 1960. To visualize overall trends, we can render the passenger count for each month into line plots. Line plots enable us to observe trends over the twelve-year timeline.
Let's unravel the first plot:

In this block of code, we use the pivot() function to rearrange the original dataframe to allow us to easily compare passenger counts for every month across all the years. This operation results in each month being an index, with each column representing a year and the cells holding the passenger count for a month in that year. We then plot this rearranged data as a line plot.
The resulting line plot presents lines for each year, with the x-axis showing the months and the y-axis representing the passenger counts. Each line's point corresponds to the passenger count for a particular month.

