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()
输出: