Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/299.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python matplotlib/seaborn中的绘图持续时间_Python_Datetime_Matplotlib_Seaborn_Duration - Fatal编程技术网

Python matplotlib/seaborn中的绘图持续时间

Python matplotlib/seaborn中的绘图持续时间,python,datetime,matplotlib,seaborn,duration,Python,Datetime,Matplotlib,Seaborn,Duration,我想用matplotlib和seaborn在Python中绘制5K和10K运行的结果。我的数据集有一个列time,其中包含一个HH:MM:SS格式的字符串对象,如00:28:50或1:17:23,其中包含比赛结果。 我通过以秒为单位计算时间来创建绘图,但为了便于阅读,我更喜欢轴上以HH:MM:SS格式的实际时间 有什么建议吗 到目前为止,我的代码是(带有虚拟数据): 您可以做的一件事是手动修改刻度: order=['5K', '10K'] palette = ['#3498db', '#ff00

我想用
matplotlib
seaborn
在Python中绘制5K和10K运行的结果。我的数据集有一个列
time
,其中包含一个
HH:MM:SS
格式的字符串对象,如
00:28:50
1:17:23
,其中包含比赛结果。 我通过以秒为单位计算时间来创建绘图,但为了便于阅读,我更喜欢轴上以
HH:MM:SS
格式的实际时间

有什么建议吗

到目前为止,我的代码是(带有虚拟数据):


您可以做的一件事是手动修改刻度:

order=['5K', '10K']
palette = ['#3498db', '#ff0080']
fig, ax = plt.subplots(figsize=(16, 8))
sns.boxplot(ax=ax, data=df, x='time_sec', y='race', hue='sex', order=order, palette=palette, orient='h', linewidth=2.5)

# get the ticks 
ticks = ax.get_xticks()

# convert the ticks to string
ax.set_xticklabels(pd.to_datetime(ticks, unit='s').strftime('%H:%M:%S'))

plt.title('Time in seconds', fontsize=16)

plt.show()
输出:


您可以做的一件事是手动修改刻度:

order=['5K', '10K']
palette = ['#3498db', '#ff0080']
fig, ax = plt.subplots(figsize=(16, 8))
sns.boxplot(ax=ax, data=df, x='time_sec', y='race', hue='sex', order=order, palette=palette, orient='h', linewidth=2.5)

# get the ticks 
ticks = ax.get_xticks()

# convert the ticks to string
ax.set_xticklabels(pd.to_datetime(ticks, unit='s').strftime('%H:%M:%S'))

plt.title('Time in seconds', fontsize=16)

plt.show()
输出: