3

I need to create a graph that will show times in a 12-hour format on a daily basis.

The message dict will contain the following:

"messages": [
{
"timeStamp": "Aug 17, 02:29 PM",
"summary": "Could not reach the endpoint",..

I want the graph to show the day of the week in a 12-hour format on the side, with the time of the error represented in the graph for each day.

df = pd.DataFrame(msg_output_dict2)
df

    appcheck name   msgdate  msgtime    DayofWeek   summary
0   AdminTool Pxy   Aug 17  12:11 AM    Wed    Could not reach the endpoint
1   AdminTool Pxy   Aug 17  12:25 AM    Wed    Could not reach the endpoint
2   AdminTool Pxy   Aug 17  12:40 AM    Wed    Could not reach the endpoint
... ... ... ... ... ... ...
1744 RecallService  Aug 23, 11:32 AM    Tue    Could not reach the endpoint
1745 rows × 5 columns

I'm using Scatter graph:

fig = px.scatter(df, x="DayofWeek", y="msgtime", color="appcheck name", symbol="appcheck name")

enter image description here

Instead of showing the msgtime as the y axis, I would like to show a 12-hour time format, with the msgtime data shown in the graph for each day.

wovano
  • 4,543
  • 5
  • 22
  • 49
David W.
  • 31
  • 2
  • 1
    I don't understand your specific question. Are you asking how to read a datetime string like `"Aug 17, 02:29 PM"` and write it out in a different format? Or are you asking how to use timestamps for a plot axis label (you haven't mentioned what plotting library you are even using)? Or are you asking how to extract that datetime string out of your json response? – Cory Kramer Aug 19 '22 at 16:55

1 Answers1

-1

I wanted to track my weight in Python, for fun. Here is an example. It would be more helpful to us if you could give us what your x and y axis are.

Here is my Python code:

import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.patches as mp

bfg = mp.Patch(color="red", label="14% body fat goal")
wot = mp.Patch(color="blue", label="weight over time")
df = pd.read_csv("./weight.csv")

plt.plot(df["Date"], df["Weight"])
plt.ylim([150, 215])
plt.axhline(y=165.0, color='r', linestyle='-')
plt.legend(handles=[bfg, wot])
ax = plt.gca()
ax.tick_params(axis='x', labelrotation=90)
plt.show()

weight.csv:

Date,Weight
May 31 2022,183.0
June 01 2022,181.4
June 02 2022,179.2
June 03 2022,180.4
June 04 2022,179.6
June 05 2022,179.2
June 06 2022,179.6
June 07 2022,179.0
June 08 2022,178.8
June 09 2022,179.2
June 10 2022,178.6
June 11 2022,178.4
June 12 2022,177.0
June 13 2022,177.0
June 14 2022,179.2
June 15 2022,180.0
June 16 2022,179.8
June 17 2022,180.2
June 18 2022,176.6
June 19 2022,176.4
June 20 2022,177.6
June 21 2022,177.8
June 22 2022,177.2
June 23 2022,176.4
June 24 2022,175.8
June 25 2022,176.8
June 26 2022,178.2
June 27 2022,176.2
June 28 2022,175.8
June 29 2022,174.2
June 30 2022,174.8
July 01 2022,174.0
July 02 2022,174.8
July 03 2022,174.8
July 04 2022,176.4
July 05 2022,174.8
July 06 2022,176.2
July 07 2022,176.2
July 08 2022,176.8
July 09 2022,176.2
July 10 2022,177.0
July 11 2022,180.0
July 12 2022,178.2

Each date entry is a tick on the x axis, where weight is the y value.

Note: you don't have to read a file to create the data frame, it was just convenient for me.

What I lack in understanding is what you are graphing against time - number of errors in the given time period, a specific type of error occurrence over a given time period, etc?

halfer
  • 19,824
  • 17
  • 99
  • 186
Shmack
  • 1,933
  • 2
  • 18
  • 23