【发布时间】:2020-07-21 02:39:59
【问题描述】:
我的数据如下所示。 Date/Time 字段为%m-%d-%Y %H:%M:%S 格式。
Date/Time Utilization
04-01-2020 10:00:00 10
04-01-2020 10:10:00 20
04-01-2020 10:20:00 50
04-01-2020 10:30:00 10
04-02-2020 15:30:00 20
04-02-2020 15:40:00 10
04-02-2020 15:50:00 10
04-07-2020 23:40:00 40
04-07-2020 23:50:00 50
我想在 Matplotlib 中绘制它,x 轴作为日期/时间,y 轴作为利用率。
当我绘制这个时,这 10 分钟的间隔中的每一个都在 X 轴上被挤压在一起(下面的屏幕截图):
我上面的代码是这样的:
def plot_graph(utilization_map):
utilization_array = []
date_array = []
for each_time in utilization_map:
utilization = utilization_map[each_time]
utilization_array.append(utilization)
human_time = convert_epoch_to_datetime_for_plots(each_time) # This converts the epoch time in %m-%d-%Y %H:%M:%S format
date_array.append(human_time)
x_axis = date_array
y_axis = utilization_array
plt.plot(x_axis, y_axis, color='b')
plt.title("Utilization")
plt.xlabel("Days")
plt.ylabel("Percent of Utilization")
plt.legend()
plt.show()
问题:我想以 X 轴标签仅以 %m-%d 或 %m-%d-%Y 格式显示的方式绘制它,并且每天间隔而不是 10 分钟,所以一直在 X 轴上没有混合在一起。我该怎么做?
【问题讨论】:
-
相关:Changing the formatting of a datetime axis in matplotlib ... Format of datetime in pyplot axis ...更多搜索
python matplotlib x axis date format site:stackoverflow.com的变体 -
提供的代码是您的函数,但这不是可重现的代码,因为您没有包含运行代码所需的所有内容。
标签: python matplotlib