Skip to main content

Different dates data plot on common x axis in 24-hour time frame using python.


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

Most Popular Topics

Unboxing & Configuring Heltec ESP32 V3 LoRa Boards – Easy Peer-to-Peer Communication Setup

  LoRa (Long Range) is a wireless communication technology designed for long-distance, unlicensed frequency, low-power data transmission. It’s widely used in IoT (Internet of Things) applications where devices need to send small amounts of data over several kilometers without relying on Wi-Fi or cellular networks. With its low power consumption and extended range, LoRa is ideal for smart agriculture, environmental monitoring, and remote sensing projects. In this guide, I’ll walk you through my LoRa implementation setup using the Heltec ESP32 V3 boards. If you haven’t already installed the Arduino IDE on your computer, make sure to install it first. it’s essential for uploading code to your LoRa boards. Once the Arduino IDE is successfully installed, it should look like the screenshot below (or similar depending on your version). From there, follow the steps outlined in this tutorial to configure your boards for peer-to-peer communication. For this project, I used two Heltec ESP32 V...

ESP32 with Neo-6M GPS Module: Hardware Serial Code & Practical Implementation Guide

In this project, I used the ESP32 WROOM-32 development board in combination with the Neo-6M GPS module to acquire real-time satellite-based location data. The hardware components were interconnected using hardware serial (UART) to ensure reliable communication between the ESP32 and the GPS module. The wiring setup is illustrated below. Neo-6M GPS Module     |      ESP32 WROOM-32        Vcc      =====>   VIN (3.3V) GND   =====>     GND     TX      =====>    GPIO16     RX     =====>   GPIO17 Snapshot of the NEO-6M GPS Module used in this project: Front View of the NEO-6M GPS Module Backside of the NEO-6M GPS Module Snapshot of the ESP32 WROOM-32 Arduino board used in this project: After the interconnecting these two boards you have to follow following procedures. Install TinyGPS++ library: Open Ardui...

How to Design and Simulate a 4-Phase Interleaved Boost Converter Using MATLAB Simulink

In this case study, I investigate the performance of a 4-phase interleaved boost converter using MATLAB Simulink. This type of DC-DC converter architecture is widely used in high-efficiency power systems due to its improved current sharing and reduced output ripple. Each phase of the converter is symmetrically designed using identical passive components: Inductors: L₁ = L₂ = L₃ = L₄ = 1.5 mH Capacitors: C₁ = C₂ = 200 μF The converter supplies an inductive load that draws a constant output current of 5 A. The input voltage is fixed at 30 V, and the converter is operated at a duty cycle (D) of 0.6. The primary simulation objectives are to analyze: The voltage gain of the converter, The output voltage ripple characteristics, And the phase current sharing behavior under these operating conditions. Simulink design of 4-phase interleaved boost converter Simulink inputs and output of design Through this design and simulation, the following steady state waveforms can be evaluated: Load voltage...

Monitor Docker Services Using Grafana, Prometheus & cAdvisor — Without Touching the CLI

  If you're running Docker containers on a server, monitoring their performance using command-line tools can be time-consuming and difficult to visualize. In this guide, I’ll show you how to monitor your Docker services using Grafana, Prometheus, and cAdvisor—all through a web interface, without relying on CLI tools after setup. You’ll be able to: Track real-time Docker container metrics Visualize system performance through a Grafana dashboard Use Prometheus to scrape and expose container metrics Deploy everything using simple Docker commands Step 1: Run Your Docker Containers Make sure your Docker containers are already running. Here’s a snapshot of my currently active containers: Step 2: Install cAdvisor in a Docker Container To collect container metrics in real time, we’ll run cAdvisor inside a dedicated Docker container. Run the cAdvisor Container: sudo docker run   --volume=/:/rootfs:ro   --volume=/var/run:/var/run:rw   --volume=/sys:/sys:ro   --volume=/var...

How MPLS Powers Modern Telecom Infrastructure: Architecture, Case Study, and Enterprise Benefits

Abstract Multiprotocol Label Switching (MPLS) is a versatile network technology that enhances the performance, reliability, and scalability of data traffic management. This article explores a case study of MPLS, detailing its architecture and key components, such as Provider Edge (PE) Routers and Provider (P) Routers. It highlights the benefits of MPLS including simplified connectivity deployment, protocol efficiency, and improved performance. Through practical analysis and examples, this content provides a comprehensive understanding of MPLS networks, their implementation, and their role in modern telecom infrastructure. Introduction Multi-Protocol Label Switching (MPLS) is a pivotal routing technique primarily utilized in telecommunication networks. In this case study, all telecom network nodes are located in specialized core rooms that maintain strict environmental conditions and uninterrupted power to ensure reliable performance. These core rooms are geographically distributed to m...

How to Create a Share Folder Between Virtual Machine and Host Computer

  In this episode, I’m going to guide you through the process of creating a shared folder between your host computer and a virtual machine (VM). This is a common challenge, as many people struggle with sharing files seamlessly between their host system and a VM. To address this issue, I’ll be demonstrating how to set up a shared folder using VMware Workstation Player, which will allow you to access files from both the host computer and the virtual machine. Having a shared folder is particularly useful for Linux beginners who are working on their lessons or projects within a virtual environment. By creating this shared folder, you’ll have a convenient way to transfer files, collaborate across different systems, and keep your work organized. This setup not only simplifies the process of file sharing but also enhances your workflow, as you won’t need to rely on external drives or other complicated methods to move files between the host and the VM. Moreover, we’ll be using this shared ...