• Home
  • Python plot with 24 hrs x and y axis using only hours and minutes from timest

Python plot with 24 hrs x and y axis using only hours and minutes from timest

To plot a graph with the x-axis representing 24 hours, and the y-axis representing hours and minutes from a timestamp, you can use the Python library Matplotlib.

First, you’ll need to convert the timestamp to a datetime object, using the built-in datetime module. This will allow you to access the hour and minute properties of the timestamp. Then you can use these properties to create the x and y axis values for the graph.

Here’s an example of how you might do this:

import matplotlib.pyplot as plt
import datetime

timestamps = [...your timestamps here...]

x = []
y = []
for timestamp in timestamps:
dt = datetime.datetime.fromtimestamp(timestamp)

plt.plot(x, y)
plt.xlabel('Time of Day (24hrs)')

In this example, the x variable will be a list of hours (0-23) and the y variable will be a list of minutes (0-59). plt.plot(x, y) create a simple line graph with x and y axis and plt.xlabel('Time of Day (24hrs)') and plt.ylabel('Minutes') will add the label to the graph respectively. The last line plt.show() will display the graph on the screen.

It’s also possible to customize the appearance of the graph, such as the colors and styles of the lines and markers, by specifying additional arguments to the plot() function or by using other functions provided by the Matplotlib library.

It’s also important to note that this is a very basic example and in practicality, it is always recommended to use robust libraries such as Seaborn , Plotly, bokeh etc for data visualization.