0

I have a plot that has on x axis time and on y axis values in percentages. The plot is drawn based on a dataframe output. As I would need to review many plots, would be good to insert some pointers of a different color. For example, each graph starts the timeline from 08:00 and finishes at 20:00. I would need a red marker at 12:00.

I have tried the following:

graph_df is a df that contains two columns: one with time and one with percentage data.

df = graph_df.loc[graph_df['time'] == "12:00"]
graph_df.plot(x="time", y="percentage", linewidth=1, kind='line')
plt.plot(df['time'], df['percentage'], 'o-', color='red')
plt.show()
plt.savefig(graph_name)

If I am using this section of the code, I am getting the marker at the correct percentage for 12:00, but always at the start of the timeline. In my case, the red dot is marked at 08:00, but with the right percentage associated.
Any idea why it's not correctly marked?

Thank you.

1 Answer 1

1

Converting the strings to datetime objects should work. Replacing your first line with

graph_df["time"] = pd.to_datetime(graph_df["time"]).dt.time
df = graph_df[graph_df["time"].apply(lambda time: time.strftime("%H:%M"))=='12:00']

should do the job

Sign up to request clarification or add additional context in comments.

1 Comment

It does exactly what I need. Thank you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.