0

I have a data frame like this

Date/Time       Unit  Value  Nest_1  ...  Nest_3  Nest_4  Nest_5  Control
0    22.1.2023    9:43:01      1  21.102  ...  23.111  21.547  22.056   21.090
1    22.1.2023    9:58:01      2  21.602  ...  21.110  22.048  21.055   22.091
2    22.1.2023   10:13:01      3  21.102  ...  23.611  21.547  23.556   21.090
3    22.1.2023   10:28:01      4  24.103  ...  26.611  25.049  27.556   22.591

I want to create a multiple scatter/line plot where each nest ("Nest_1", "Nest_2", etc.) is the Y, and Value is x. However, I wish the x axis to be in a time scale, like date or day and hour (extracted from Data/Time and Unit columns).

Here's the code for the plot I've written this far. I think its fine, I just need to get the x axis going on.

import pandas as pd
import matplotlib.pyplot as plt

# reading the txt file
df = pd.read_excel ('mypath.xlsx', engine='openpyxl')

# Create a single figure and axis
fig, ax = plt.subplots()

# Scatter plot for each sensor:

df.plot.scatter(x='Value', y='Nest_1', c='blue', label='Nest 1', ax=ax)
df.plot.scatter(x='Value', y='Nest_2', c='Orange', label='Nest 2', ax=ax)
df.plot.scatter(x='Value', y='Nest_3', c='Grey', label='Nest 3', ax=ax)
df.plot.scatter(x='Value', y='Nest_4', c='Yellow', label='Nest 4', ax=ax)
df.plot.scatter(x='Value', y='Nest_5', c='Green', label='Nest 5', ax=ax)
df.plot.scatter(x='Value', y='Control',c='Red', marker='X', label='Control', ax=ax)

plt.xlabel('Time')
plt.ylabel('Temperature [°C]')
plt.title('Temperature')
plt.legend()
plt.show()
Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
  • 1. `df['Datetime'] = pd.to_datetime(df['Date/Time'] + ' ' + df['Unit'], dayfirst=True)` 2. `df['Time'] = df.Datetime.dt.time` 3. `df.iloc[:, [3, 4, 5, 6, 7, 9]].plot(x='Time', marker='.', ylabel='Temperature [°C]', title='Temperature')` and [plot](https://i.stack.imgur.com/PekWf.png) – Trenton McKinney Aug 31 '23 at 15:07

0 Answers0