Contents
Line Charts and Area Charts
Line charts are the best choice for showing change over time. Area charts add emphasis on volume. This topic shows how to plot trends clearly and how to avoid the common traps.
a. Plotting Trends with Line Charts
A line chart connects data points in time order. It makes the direction and speed of change easy to see. It works for sales, temperatures, website visits, and many other measures.
When your data is in a DataFrame with a date column, convert the column to a date type first and then plot.
df["date"] = pd.to_datetime(df["date"])
fig, ax = plt.subplots(figsize=(10, 5))
ax.plot(df["date"], df["sales"])
ax.set_title("Daily Sales")
plt.show()Matplotlib handles dates well and spaces the labels automatically. If labels overlap, rotate them with plt.xticks(rotation=45).
b. Comparing Multiple Lines
You can place several lines on one chart to compare trends, such as sales in different regions. Give each line a label and show a legend so readers know which is which.
for region in ["North", "South", "East"]:
data = df[df["region"] == region]
ax.plot(data["date"], data["sales"], label=region)
ax.legend()Limit the chart to about four or five lines. With more, the chart looks like tangled spaghetti. In that case, highlight one or two lines in color and make the others gray, or split the data into separate small charts.
Use clearly different colors and keep the same colors for the same categories across all your charts.
c. Creating Area Charts
An area chart is a line chart with the space below the line filled in. It draws attention to the size of the values over time. Use fill_between() or the stackplot() function.
ax.plot(df["date"], df["sales"])
ax.fill_between(df["date"], df["sales"], alpha=0.3)The alpha setting makes the color see-through so that gridlines remain visible. Stacked area charts show how parts add up to a total over time.
Use stacked area charts with care. Only the bottom layer has a clear baseline, so the shapes of upper layers can be hard to compare.
d. Common Line Chart Mistakes
One common mistake is using a line chart for unrelated categories, such as products. A line suggests a connection between points, so it should be used only for ordered data like time.
Another mistake is a misleading vertical axis. Cutting the axis can make a small change look dramatic. Think about whether starting at zero or showing a narrower range is more honest for your data.
Also avoid too many lines, missing labels, and uneven time gaps. If dates are missing, a line may hide the gap. Check your data and show gaps clearly so the picture stays accurate.
Data Visualization Tutorial
Wesline Rinisha








