plot the x axis as MM:SS instead of integer in a histogram

I have ambulance response time data as seconds. For example (32, 158, 36, 459, 830, 396). I am able to make a Matplotlib histogram binning the data into 60 second increments. On the x axis label the data is labelled as 0 – 60 – 120 – 180 etc. I would like the x axis label to show 00:00 – 01:00 – 02:00 – 03:00 etc. In other words, instead of seconds as integer values, it should show seconds formatted as mm:ss.
The code below comes close but I am not able to make it work. The code below only returns 00:00 for all bins.
How can I label the x axis of a histogram as mm:ss instead of integers?

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># import the libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
# generate a dataframe of values from 0 to 1800 (zero seconds to 1800 seconds which is 30 minutes)
df = pd.DataFrame(np.random.randint(0,1800, size=(1000, 1)), columns=list('A'))
start_value = 0 # the start value is zero seconds
end_value = 1800 # the end value is 1800 seconds (30 minutes)
increment_by_value = 60 # increment by one minute
# set up the nuts and bolts of the histogram
fig = plt.figure()
fig.set_dpi(100)
fig.set_size_inches(8, 6.5)
ax = fig.add_subplot(111)
# generate a histogram
plt.hist(df.A, bins=np.arange(start_value, end_value, increment_by_value), color='Purple', label='Response Time', edgecolor = 'Gray', linewidth = 1.0)
# not sure how this works. I would hope that it formats 75 seconds to 01:15
myFmt = mdates.DateFormatter('%M:%S')
ax.xaxis.set_major_formatter(myFmt)
# the x ticks line up with the bars. In other words, every 60 seconds
plt.xticks(np.arange(start_value, end_value, increment_by_value), rotation='vertical')
# set up the title and the labels
plt.title("Cardiac Arrest Response Time" + 'n' + '(Interval in Seconds)')
plt.xlabel("Bins of 1 minute (in seconds)")
plt.ylabel("Calls")
plt.legend()
plt.show()
</code>
<code># import the libraries import numpy as np import pandas as pd import matplotlib.pyplot as plt import matplotlib.dates as mdates # generate a dataframe of values from 0 to 1800 (zero seconds to 1800 seconds which is 30 minutes) df = pd.DataFrame(np.random.randint(0,1800, size=(1000, 1)), columns=list('A')) start_value = 0 # the start value is zero seconds end_value = 1800 # the end value is 1800 seconds (30 minutes) increment_by_value = 60 # increment by one minute # set up the nuts and bolts of the histogram fig = plt.figure() fig.set_dpi(100) fig.set_size_inches(8, 6.5) ax = fig.add_subplot(111) # generate a histogram plt.hist(df.A, bins=np.arange(start_value, end_value, increment_by_value), color='Purple', label='Response Time', edgecolor = 'Gray', linewidth = 1.0) # not sure how this works. I would hope that it formats 75 seconds to 01:15 myFmt = mdates.DateFormatter('%M:%S') ax.xaxis.set_major_formatter(myFmt) # the x ticks line up with the bars. In other words, every 60 seconds plt.xticks(np.arange(start_value, end_value, increment_by_value), rotation='vertical') # set up the title and the labels plt.title("Cardiac Arrest Response Time" + 'n' + '(Interval in Seconds)') plt.xlabel("Bins of 1 minute (in seconds)") plt.ylabel("Calls") plt.legend() plt.show() </code>
# import the libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
# generate a dataframe of values from 0 to 1800 (zero seconds to 1800 seconds which is 30 minutes)
df = pd.DataFrame(np.random.randint(0,1800, size=(1000, 1)), columns=list('A'))

start_value = 0 # the start value is zero seconds
end_value = 1800 # the end value is 1800 seconds (30 minutes)
increment_by_value = 60 # increment by one minute

# set up the nuts and bolts of the histogram
fig = plt.figure()
fig.set_dpi(100)
fig.set_size_inches(8, 6.5)
ax = fig.add_subplot(111)

# generate a histogram
plt.hist(df.A, bins=np.arange(start_value, end_value, increment_by_value), color='Purple', label='Response Time', edgecolor = 'Gray', linewidth = 1.0)

# not sure how this works. I would hope that it formats 75 seconds to 01:15
myFmt = mdates.DateFormatter('%M:%S')
ax.xaxis.set_major_formatter(myFmt)

# the x ticks line up with the bars. In other words, every 60 seconds
plt.xticks(np.arange(start_value, end_value, increment_by_value), rotation='vertical')

# set up the title and the labels
plt.title("Cardiac Arrest Response Time" + 'n' + '(Interval in Seconds)')
plt.xlabel("Bins of 1 minute (in seconds)")
plt.ylabel("Calls")
plt.legend()
plt.show()

I suspect the issue is because DateFormatter expects input in days since the standard epoch.

A quick way to get around this is to remove mdates altogether, and just define a simple FuncFormatter from the matplotlib.ticker module. For example, replace these two lines:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>myFmt = mdates.DateFormatter('%M:%S')
ax.xaxis.set_major_formatter(myFmt)
</code>
<code>myFmt = mdates.DateFormatter('%M:%S') ax.xaxis.set_major_formatter(myFmt) </code>
myFmt = mdates.DateFormatter('%M:%S')
ax.xaxis.set_major_formatter(myFmt)

with

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import matplotlib.ticker as ticker
# Formatter function to convert seconds to MM:SS format
def seconds_to_minutes(seconds, pos):
m = int(seconds // 60)
s = int(seconds % 60)
return f'{m:02d}:{s:02d}'
ax.xaxis.set_major_formatter(ticker.FuncFormatter(seconds_to_minutes))
</code>
<code>import matplotlib.ticker as ticker # Formatter function to convert seconds to MM:SS format def seconds_to_minutes(seconds, pos): m = int(seconds // 60) s = int(seconds % 60) return f'{m:02d}:{s:02d}' ax.xaxis.set_major_formatter(ticker.FuncFormatter(seconds_to_minutes)) </code>
import matplotlib.ticker as ticker

# Formatter function to convert seconds to MM:SS format
def seconds_to_minutes(seconds, pos):
    m = int(seconds // 60)
    s = int(seconds % 60)
    return f'{m:02d}:{s:02d}'

ax.xaxis.set_major_formatter(ticker.FuncFormatter(seconds_to_minutes))

0

A note of gratitude to tmdavison. Here is the full worked example for others who have this issue.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># import the libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.ticker as ticker
# generate a dataframe of values from 0 to 1800 (zero seconds to 1800 seconds which is 30 minutes)
df = pd.DataFrame(np.random.randint(0,1800, size=(1000, 1)), columns=list('A'))
start_value = 0 # the start value is zero seconds
end_value = 1800 # the end value is 1800 seconds (30 minutes)
increment_by_value = 60 # increment by one minute
# set up the nuts and bolts of the histogram
fig = plt.figure()
fig.set_dpi(100)
fig.set_size_inches(8, 6.5)
ax = fig.add_subplot(111)
# generate a histogram
plt.hist(df.A, bins=np.arange(start_value, end_value, increment_by_value), color='Purple', label='Response Time', edgecolor = 'Gray', linewidth = 1.0)
# Formatter function to convert seconds to MM:SS format
def seconds_to_minutes(seconds, pos):
m = int(seconds // 60)
s = int(seconds % 60)
return f'{m:02d}:{s:02d}'
ax.xaxis.set_major_formatter(ticker.FuncFormatter(seconds_to_minutes))
# the x ticks line up with the bars. In other words, every 60 seconds
plt.xticks(np.arange(start_value, end_value, increment_by_value), rotation='vertical')
# set up the title and the labels
plt.title("Cardiac Arrest Response Time" + 'n' + '(Interval in Seconds)')
plt.xlabel("Bins of 1 minute (in seconds)")
plt.ylabel("Calls")
plt.legend()
plt.show()
</code>
<code># import the libraries import numpy as np import pandas as pd import matplotlib.pyplot as plt import matplotlib.dates as mdates import matplotlib.ticker as ticker # generate a dataframe of values from 0 to 1800 (zero seconds to 1800 seconds which is 30 minutes) df = pd.DataFrame(np.random.randint(0,1800, size=(1000, 1)), columns=list('A')) start_value = 0 # the start value is zero seconds end_value = 1800 # the end value is 1800 seconds (30 minutes) increment_by_value = 60 # increment by one minute # set up the nuts and bolts of the histogram fig = plt.figure() fig.set_dpi(100) fig.set_size_inches(8, 6.5) ax = fig.add_subplot(111) # generate a histogram plt.hist(df.A, bins=np.arange(start_value, end_value, increment_by_value), color='Purple', label='Response Time', edgecolor = 'Gray', linewidth = 1.0) # Formatter function to convert seconds to MM:SS format def seconds_to_minutes(seconds, pos): m = int(seconds // 60) s = int(seconds % 60) return f'{m:02d}:{s:02d}' ax.xaxis.set_major_formatter(ticker.FuncFormatter(seconds_to_minutes)) # the x ticks line up with the bars. In other words, every 60 seconds plt.xticks(np.arange(start_value, end_value, increment_by_value), rotation='vertical') # set up the title and the labels plt.title("Cardiac Arrest Response Time" + 'n' + '(Interval in Seconds)') plt.xlabel("Bins of 1 minute (in seconds)") plt.ylabel("Calls") plt.legend() plt.show() </code>
# import the libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.ticker as ticker

# generate a dataframe of values from 0 to 1800 (zero seconds to 1800 seconds which is 30 minutes)
df = pd.DataFrame(np.random.randint(0,1800, size=(1000, 1)), columns=list('A'))

start_value = 0 # the start value is zero seconds
end_value = 1800 # the end value is 1800 seconds (30 minutes)
increment_by_value = 60 # increment by one minute

# set up the nuts and bolts of the histogram
fig = plt.figure()
fig.set_dpi(100)
fig.set_size_inches(8, 6.5)
ax = fig.add_subplot(111)

# generate a histogram
plt.hist(df.A, bins=np.arange(start_value, end_value, increment_by_value), color='Purple', label='Response Time', edgecolor = 'Gray', linewidth = 1.0)

# Formatter function to convert seconds to MM:SS format
def seconds_to_minutes(seconds, pos):
    m = int(seconds // 60)
    s = int(seconds % 60)
    return f'{m:02d}:{s:02d}'

ax.xaxis.set_major_formatter(ticker.FuncFormatter(seconds_to_minutes))

# the x ticks line up with the bars. In other words, every 60 seconds
plt.xticks(np.arange(start_value, end_value, increment_by_value), rotation='vertical')

# set up the title and the labels
plt.title("Cardiac Arrest Response Time" + 'n' + '(Interval in Seconds)')
plt.xlabel("Bins of 1 minute (in seconds)")
plt.ylabel("Calls")
plt.legend()
plt.show()

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa

plot the x axis as MM:SS instead of integer in a histogram

I have ambulance response time data as seconds. For example (32, 158, 36, 459, 830, 396). I am able to make a Matplotlib histogram binning the data into 60 second increments. On the x axis label the data is labelled as 0 – 60 – 120 – 180 etc. I would like the x axis label to show 00:00 – 01:00 – 02:00 – 03:00 etc. In other words, instead of seconds as integer values, it should show seconds formatted as mm:ss.
The code below comes close but I am not able to make it work. The code below only returns 00:00 for all bins.
How can I label the x axis of a histogram as mm:ss instead of integers?

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># import the libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
# generate a dataframe of values from 0 to 1800 (zero seconds to 1800 seconds which is 30 minutes)
df = pd.DataFrame(np.random.randint(0,1800, size=(1000, 1)), columns=list('A'))
start_value = 0 # the start value is zero seconds
end_value = 1800 # the end value is 1800 seconds (30 minutes)
increment_by_value = 60 # increment by one minute
# set up the nuts and bolts of the histogram
fig = plt.figure()
fig.set_dpi(100)
fig.set_size_inches(8, 6.5)
ax = fig.add_subplot(111)
# generate a histogram
plt.hist(df.A, bins=np.arange(start_value, end_value, increment_by_value), color='Purple', label='Response Time', edgecolor = 'Gray', linewidth = 1.0)
# not sure how this works. I would hope that it formats 75 seconds to 01:15
myFmt = mdates.DateFormatter('%M:%S')
ax.xaxis.set_major_formatter(myFmt)
# the x ticks line up with the bars. In other words, every 60 seconds
plt.xticks(np.arange(start_value, end_value, increment_by_value), rotation='vertical')
# set up the title and the labels
plt.title("Cardiac Arrest Response Time" + 'n' + '(Interval in Seconds)')
plt.xlabel("Bins of 1 minute (in seconds)")
plt.ylabel("Calls")
plt.legend()
plt.show()
</code>
<code># import the libraries import numpy as np import pandas as pd import matplotlib.pyplot as plt import matplotlib.dates as mdates # generate a dataframe of values from 0 to 1800 (zero seconds to 1800 seconds which is 30 minutes) df = pd.DataFrame(np.random.randint(0,1800, size=(1000, 1)), columns=list('A')) start_value = 0 # the start value is zero seconds end_value = 1800 # the end value is 1800 seconds (30 minutes) increment_by_value = 60 # increment by one minute # set up the nuts and bolts of the histogram fig = plt.figure() fig.set_dpi(100) fig.set_size_inches(8, 6.5) ax = fig.add_subplot(111) # generate a histogram plt.hist(df.A, bins=np.arange(start_value, end_value, increment_by_value), color='Purple', label='Response Time', edgecolor = 'Gray', linewidth = 1.0) # not sure how this works. I would hope that it formats 75 seconds to 01:15 myFmt = mdates.DateFormatter('%M:%S') ax.xaxis.set_major_formatter(myFmt) # the x ticks line up with the bars. In other words, every 60 seconds plt.xticks(np.arange(start_value, end_value, increment_by_value), rotation='vertical') # set up the title and the labels plt.title("Cardiac Arrest Response Time" + 'n' + '(Interval in Seconds)') plt.xlabel("Bins of 1 minute (in seconds)") plt.ylabel("Calls") plt.legend() plt.show() </code>
# import the libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
# generate a dataframe of values from 0 to 1800 (zero seconds to 1800 seconds which is 30 minutes)
df = pd.DataFrame(np.random.randint(0,1800, size=(1000, 1)), columns=list('A'))

start_value = 0 # the start value is zero seconds
end_value = 1800 # the end value is 1800 seconds (30 minutes)
increment_by_value = 60 # increment by one minute

# set up the nuts and bolts of the histogram
fig = plt.figure()
fig.set_dpi(100)
fig.set_size_inches(8, 6.5)
ax = fig.add_subplot(111)

# generate a histogram
plt.hist(df.A, bins=np.arange(start_value, end_value, increment_by_value), color='Purple', label='Response Time', edgecolor = 'Gray', linewidth = 1.0)

# not sure how this works. I would hope that it formats 75 seconds to 01:15
myFmt = mdates.DateFormatter('%M:%S')
ax.xaxis.set_major_formatter(myFmt)

# the x ticks line up with the bars. In other words, every 60 seconds
plt.xticks(np.arange(start_value, end_value, increment_by_value), rotation='vertical')

# set up the title and the labels
plt.title("Cardiac Arrest Response Time" + 'n' + '(Interval in Seconds)')
plt.xlabel("Bins of 1 minute (in seconds)")
plt.ylabel("Calls")
plt.legend()
plt.show()

I suspect the issue is because DateFormatter expects input in days since the standard epoch.

A quick way to get around this is to remove mdates altogether, and just define a simple FuncFormatter from the matplotlib.ticker module. For example, replace these two lines:

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>myFmt = mdates.DateFormatter('%M:%S')
ax.xaxis.set_major_formatter(myFmt)
</code>
<code>myFmt = mdates.DateFormatter('%M:%S') ax.xaxis.set_major_formatter(myFmt) </code>
myFmt = mdates.DateFormatter('%M:%S')
ax.xaxis.set_major_formatter(myFmt)

with

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code>import matplotlib.ticker as ticker
# Formatter function to convert seconds to MM:SS format
def seconds_to_minutes(seconds, pos):
m = int(seconds // 60)
s = int(seconds % 60)
return f'{m:02d}:{s:02d}'
ax.xaxis.set_major_formatter(ticker.FuncFormatter(seconds_to_minutes))
</code>
<code>import matplotlib.ticker as ticker # Formatter function to convert seconds to MM:SS format def seconds_to_minutes(seconds, pos): m = int(seconds // 60) s = int(seconds % 60) return f'{m:02d}:{s:02d}' ax.xaxis.set_major_formatter(ticker.FuncFormatter(seconds_to_minutes)) </code>
import matplotlib.ticker as ticker

# Formatter function to convert seconds to MM:SS format
def seconds_to_minutes(seconds, pos):
    m = int(seconds // 60)
    s = int(seconds % 60)
    return f'{m:02d}:{s:02d}'

ax.xaxis.set_major_formatter(ticker.FuncFormatter(seconds_to_minutes))

0

A note of gratitude to tmdavison. Here is the full worked example for others who have this issue.

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
<code># import the libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.ticker as ticker
# generate a dataframe of values from 0 to 1800 (zero seconds to 1800 seconds which is 30 minutes)
df = pd.DataFrame(np.random.randint(0,1800, size=(1000, 1)), columns=list('A'))
start_value = 0 # the start value is zero seconds
end_value = 1800 # the end value is 1800 seconds (30 minutes)
increment_by_value = 60 # increment by one minute
# set up the nuts and bolts of the histogram
fig = plt.figure()
fig.set_dpi(100)
fig.set_size_inches(8, 6.5)
ax = fig.add_subplot(111)
# generate a histogram
plt.hist(df.A, bins=np.arange(start_value, end_value, increment_by_value), color='Purple', label='Response Time', edgecolor = 'Gray', linewidth = 1.0)
# Formatter function to convert seconds to MM:SS format
def seconds_to_minutes(seconds, pos):
m = int(seconds // 60)
s = int(seconds % 60)
return f'{m:02d}:{s:02d}'
ax.xaxis.set_major_formatter(ticker.FuncFormatter(seconds_to_minutes))
# the x ticks line up with the bars. In other words, every 60 seconds
plt.xticks(np.arange(start_value, end_value, increment_by_value), rotation='vertical')
# set up the title and the labels
plt.title("Cardiac Arrest Response Time" + 'n' + '(Interval in Seconds)')
plt.xlabel("Bins of 1 minute (in seconds)")
plt.ylabel("Calls")
plt.legend()
plt.show()
</code>
<code># import the libraries import numpy as np import pandas as pd import matplotlib.pyplot as plt import matplotlib.dates as mdates import matplotlib.ticker as ticker # generate a dataframe of values from 0 to 1800 (zero seconds to 1800 seconds which is 30 minutes) df = pd.DataFrame(np.random.randint(0,1800, size=(1000, 1)), columns=list('A')) start_value = 0 # the start value is zero seconds end_value = 1800 # the end value is 1800 seconds (30 minutes) increment_by_value = 60 # increment by one minute # set up the nuts and bolts of the histogram fig = plt.figure() fig.set_dpi(100) fig.set_size_inches(8, 6.5) ax = fig.add_subplot(111) # generate a histogram plt.hist(df.A, bins=np.arange(start_value, end_value, increment_by_value), color='Purple', label='Response Time', edgecolor = 'Gray', linewidth = 1.0) # Formatter function to convert seconds to MM:SS format def seconds_to_minutes(seconds, pos): m = int(seconds // 60) s = int(seconds % 60) return f'{m:02d}:{s:02d}' ax.xaxis.set_major_formatter(ticker.FuncFormatter(seconds_to_minutes)) # the x ticks line up with the bars. In other words, every 60 seconds plt.xticks(np.arange(start_value, end_value, increment_by_value), rotation='vertical') # set up the title and the labels plt.title("Cardiac Arrest Response Time" + 'n' + '(Interval in Seconds)') plt.xlabel("Bins of 1 minute (in seconds)") plt.ylabel("Calls") plt.legend() plt.show() </code>
# import the libraries
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import matplotlib.dates as mdates
import matplotlib.ticker as ticker

# generate a dataframe of values from 0 to 1800 (zero seconds to 1800 seconds which is 30 minutes)
df = pd.DataFrame(np.random.randint(0,1800, size=(1000, 1)), columns=list('A'))

start_value = 0 # the start value is zero seconds
end_value = 1800 # the end value is 1800 seconds (30 minutes)
increment_by_value = 60 # increment by one minute

# set up the nuts and bolts of the histogram
fig = plt.figure()
fig.set_dpi(100)
fig.set_size_inches(8, 6.5)
ax = fig.add_subplot(111)

# generate a histogram
plt.hist(df.A, bins=np.arange(start_value, end_value, increment_by_value), color='Purple', label='Response Time', edgecolor = 'Gray', linewidth = 1.0)

# Formatter function to convert seconds to MM:SS format
def seconds_to_minutes(seconds, pos):
    m = int(seconds // 60)
    s = int(seconds % 60)
    return f'{m:02d}:{s:02d}'

ax.xaxis.set_major_formatter(ticker.FuncFormatter(seconds_to_minutes))

# the x ticks line up with the bars. In other words, every 60 seconds
plt.xticks(np.arange(start_value, end_value, increment_by_value), rotation='vertical')

# set up the title and the labels
plt.title("Cardiac Arrest Response Time" + 'n' + '(Interval in Seconds)')
plt.xlabel("Bins of 1 minute (in seconds)")
plt.ylabel("Calls")
plt.legend()
plt.show()

Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa Dịch vụ tổ chức sự kiện 5 sao Thông tin về chúng tôi Dịch vụ sinh nhật bé trai Dịch vụ sinh nhật bé gái Sự kiện trọn gói Các tiết mục giải trí Dịch vụ bổ trợ Tiệc cưới sang trọng Dịch vụ khai trương Tư vấn tổ chức sự kiện Hình ảnh sự kiện Cập nhật tin tức Liên hệ ngay Thuê chú hề chuyên nghiệp Tiệc tất niên cho công ty Trang trí tiệc cuối năm Tiệc tất niên độc đáo Sinh nhật bé Hải Đăng Sinh nhật đáng yêu bé Khánh Vân Sinh nhật sang trọng Bích Ngân Tiệc sinh nhật bé Thanh Trang Dịch vụ ông già Noel Xiếc thú vui nhộn Biểu diễn xiếc quay đĩa Dịch vụ tổ chức tiệc uy tín Khám phá dịch vụ của chúng tôi Tiệc sinh nhật cho bé trai Trang trí tiệc cho bé gái Gói sự kiện chuyên nghiệp Chương trình giải trí hấp dẫn Dịch vụ hỗ trợ sự kiện Trang trí tiệc cưới đẹp Khởi đầu thành công với khai trương Chuyên gia tư vấn sự kiện Xem ảnh các sự kiện đẹp Tin mới về sự kiện Kết nối với đội ngũ chuyên gia Chú hề vui nhộn cho tiệc sinh nhật Ý tưởng tiệc cuối năm Tất niên độc đáo Trang trí tiệc hiện đại Tổ chức sinh nhật cho Hải Đăng Sinh nhật độc quyền Khánh Vân Phong cách tiệc Bích Ngân Trang trí tiệc bé Thanh Trang Thuê dịch vụ ông già Noel chuyên nghiệp Xem xiếc khỉ đặc sắc Xiếc quay đĩa thú vị
Trang chủ Giới thiệu Sinh nhật bé trai Sinh nhật bé gái Tổ chức sự kiện Biểu diễn giải trí Dịch vụ khác Trang trí tiệc cưới Tổ chức khai trương Tư vấn dịch vụ Thư viện ảnh Tin tức - sự kiện Liên hệ Chú hề sinh nhật Trang trí YEAR END PARTY công ty Trang trí tất niên cuối năm Trang trí tất niên xu hướng mới nhất Trang trí sinh nhật bé trai Hải Đăng Trang trí sinh nhật bé Khánh Vân Trang trí sinh nhật Bích Ngân Trang trí sinh nhật bé Thanh Trang Thuê ông già Noel phát quà Biểu diễn xiếc khỉ Xiếc quay đĩa
Thiết kế website Thiết kế website Thiết kế website Cách kháng tài khoản quảng cáo Mua bán Fanpage Facebook Dịch vụ SEO Tổ chức sinh nhật