0

I have a small set of data covering the length of time it takes to carry out a task;

Model A min time 5:40 max time 5:49

Model B min time 36:37 max time 37:12

Model C min time 18:56 max time 20:18

Model D min time 5:57 max time 6:34

The code I intend to use to display this data will be as follows:

def show_performance_stats(df):
    sns.set(style='darkgrid')

    sns.set(font_scale=1)
    plt.rcParams["figure.figsize"] = (6.5,4) 
    plt.plot(df['MinTime'], 'bo', label="Min Time")
    plt.plot(df['MaxTime'], 'go', label="Max Time")

    # Label the plot.
    plt.title("Performace for each category")
    plt.ylabel("Time")
    plt.legend()
    plt.xticks([0, 1, 2, 3], df['Models']) 
    plt.yticks([0, 10, 20, 30, 40])
    chart = Chart.get_graph_file("Performance")
    plt.savefig(chart)   
    plt.close()         # Use close to ensure plt is reset for future use 

I have not run this code yet. I want to know how to represent time in this graph, bearing in mind that minutes and seconds scale to 60 rather than 100?

Zephyr
  • 11,891
  • 53
  • 45
  • 80
arame3333
  • 9,887
  • 26
  • 122
  • 205
  • This question is not reproducible without **data**. This question needs a [SSCCE](http://sscce.org/). Please see [How to provide a reproducible dataframe](https://stackoverflow.com/q/52413246/7758804), then **[edit] your question**, and paste the clipboard into a code block. Always provide a [mre] **with code, data, errors, current output, and expected output, as [formatted text](https://stackoverflow.com/help/formatting)**. If relevant, plot images are okay. If you don't include an mre, it is likely the question will be downvoted, closed, and deleted. – Trenton McKinney Sep 23 '21 at 14:30

1 Answers1

0

Matplotlib does handle datetimes well, check out this example:

from datetime import datetime as dt
from datetime import timedelta as td

import matplotlib.pyplot as plt

start = dt(2021, 1, 1, 0, 0, 0)
sec = td(seconds=1)
N = 100

x = [start + i * sec for i in range(N)]
y = range(N)

plt.plot(x, y)
plt.show()

Produces

enter image description here

matplotlib.dates offers more options how to customize how is the datetime formatted, see here for more details:

https://matplotlib.org/stable/gallery/text_labels_and_annotations/date.html#sphx-glr-gallery-text-labels-and-annotations-date-py

Roman Pavelka
  • 3,736
  • 2
  • 11
  • 28