Here, I used a different method to represent hourly data across various dates. I converted specific dates to common dates and then plotted the time series data on a 24-hour time frame along the x-axis, with traffic patterns on the y-axis.
import os
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
from datetime import datetime
import matplotlib.dates
import matplotlib.dates as md
path = 'datasheet.csv'
data = pd.read_csv(path)
data.head()
# Convert data to DataFrame
df = pd.DataFrame({'Date&Time': data['Date'] , 'DL': data['DL']/1000000000, 'UL': data['UL']/1000000000})
# Replace all Date&Time with '02/02/2024'
df['Date&Time'] = '02/02/2024 ' + df['Date&Time'].str.split(' ', expand=True)[1]
# Convert 'Date&Time' column to datetime format
df['Formated_Date'] = pd.to_datetime(df['Date&Time'], format='%m/%d/%Y %H:%M')
# Create subplots
fig, ax = plt.subplots(figsize=(8,6))
#add grid for graph
plt.grid(color = 'green', linestyle = '--', linewidth = 0.5)
# Plot scatter plot
ax.scatter(df['Formated_Date'], df['DL'], color="red", label='UL', s=10)
# Set x-axis limits
ax.set_xlim(datetime(2024, 2, 2, 0, 0)-pd.Timedelta(1,'h'), datetime(2024, 2, 2, 23, 59)+pd.Timedelta(1,'h'))
# Set x-axis ticks to hourly intervals
ax.xaxis.set_major_locator(md.HourLocator(interval=2))
ax.xaxis.set_major_formatter(md.DateFormatter('%H:%M'))
# Rotate x-axis labels for better visibility
fig.autofmt_xdate()
# Set labels and title
plt.xlabel('Hours')
plt.ylabel('DL (Gbps)')
plt.title('DL Traffic Over Time')
# Add legend
plt.legend()
# Show plot
plt.show()
The output of the code can be represented as follows.
Comments
Post a Comment