I need help formatting the x-axis with date and time

Can anyone guide me how to format the x-axis with date and time.
Here is the graphic as I currently do it::

This is the data file (csv):

10-2-2024 00:03:29,0,12.08,0,0
10-2-2024 00:32:19,0,12.06,0,0
10-2-2024 02:14:45,0,12,0,0
10-2-2024 03:57:31,0,11.93,0,0
10-2-2024 05:40:07,0,11.82,0,0
10-2-2024 07:22:58,3,11.7,0.1,13.32
10-2-2024 09:06:23,3,13.11,16.1,30.8
10-2-2024 10:49:24,3,12.98,7.5,29.95
10-2-2024 12:32:34,3,13.74,33.6,27.1
10-2-2024 14:15:20,3,13.27,6.4,29.42
10-2-2024 15:58:55,3,13.08,0.3,15.46
10-2-2024 17:42:51,0,13.03,0,0
10-2-2024 19:26:41,0,12.9,0,0
10-2-2024 21:10:26,0,12.69,0,0
10-2-2024 22:53:47,0,12.2,0,0

Here my code:


# Import
import datetime
import pandas as pd
from matplotlib import pyplot as plt
from datetime import timedelta

# Datumstrings definieren
filedatum = datetime.datetime.now()
datumg = filedatum - timedelta(days = 1)
datumgestern = datumg.strftime('%d.%m.%Y')

# Diagramm formatieren
plt.rcParams["figure.figsize"] = [7.50, 3.00]
plt.rcParams["figure.autolayout"] = True

#Lesen Heutedatei
columns = ["DateTime", "Volt"]
df = pd.read_csv("heute_kom_test.csv", usecols=columns)

# Diagramm drucken
plt.plot(df.DateTime, df.Volt)
plt.title('MPPT '+ datumgestern)


First, I would have liked to put limits on the x-axis


Your DateTime column is currently a Series of strings. See, e.g., IO tools (text, CSV, HDF5, …) — pandas 2.2.0 documentation for Pandas information to convert them to more specific types.

Note that your timestamps in the CSV are in an order that may be ambiguous for parsing.

Thank you.
What would be a correct order for parsing?
Can you please show me a few examples of the correct procedure?
I’m pretty new to programming things like this. I learn best with examples.

Many thanks.

An easy/standard date order to parse is bigger values to smallest values - - > yyyymmdd-HHMMSS, instead of your mmddyyyy-HHMMSS, but pandas and many other tools can parse dates in any order as long as you tell the parser what that is.

For example you could use strptime (short for STRing Parse TIME) on your string column with date_format = “%m%d%Y %H:%M:%S”. See strftime.org for more codes.