简体   繁体   English

如何在 Python 中以分钟为 plot x 轴?

[英]How to plot x axis with minutes in Python?

I'm trying to plot x axis with every 60 minutes during,and y axis with a list.我正在尝试 plot x 轴每 60 分钟一次,y 轴带有一个列表。

I've tried code:我试过代码:

import pandas as pd
import matplotlib.pyplot as plt

date_time = ['08:30', '09:30', '10:30', '11:30', '12:30', '13:30', '14:30']

date_time = pd.to_datetime(date_time)
temp = [2, 4, 6, 4, 6,9,8]

DF = pd.DataFrame()
DF['temp'] = temp
DF = DF.set_index(date_time)

fig, ax = plt.subplots()
fig.subplots_adjust(bottom=0.3)
plt.xticks(rotation=90)
plt.plot(DF)

But the out put is x axis is like this one: plot x-axis as date in matplotlib ,the x axis is not minutes but date,但输出是 x 轴是这样的: plot x 轴作为 matplotlib 中的日期,x 轴不是分钟而是日期,

my expected values on the X-axis are like:我在 X 轴上的预期值如下:

'08:30' '09:30' '10:30' '11:30''12:30' '13:30' '14:30'

or或者

'08:30' '08:40' '08:50' '08:60' .... '15:00'

So how can I convert the date into the minutes data that I need,and also how can I convert the line into curve?那么如何将日期转换为我需要的分钟数据,以及如何将直线转换为曲线呢?

Any friends can hlep?有朋友可以帮忙吗?

Update the axis formatter:更新轴格式化程序:

matplotlib.dates as mdates 
ax.xaxis.set_major_formatter(mdates.DateFormatter("%H:%M"))
plt.plot(DF)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 Python 中将分钟时间设置为 Matplotlib plot 的 x 轴? - How to set minutes time as x-axis of a Matplotlib plot in Python? python-如何使用重复的x轴绘制数据 - python - How to plot data with repeating x axis 以日期时间为索引绘制数据框,仅在 python 的 x 轴上显示小时、分钟和秒 - plot dataframe with datetime as index and only display hours, minutes, and seconds on x-axis in python Python plot 具有 24 小时 x 和 y 轴,仅使用时间戳的小时和分钟 - Python plot with 24 hrs x and y axis using only hours and minutes from timestamp 如图所示,x 轴为 plot 天,y 轴为时间,热图 plot 为 python 中的值? - How to plot day in x axis, time in y axis and a heatmap plot for the values in python as shown in the figure? 如何在python中找到带有x轴的图的交点? - How to find intersection point of a plot with x-axis in python? 如何在Python中从数据框绘制带有x和y轴的直方图 - How to plot histogram with x and y axis from dataframe in python Python和plot():如何限制x轴刻度(标签)的数量 - Python and plot() : how to limit the number of x-axis ticks (labels) 如何在 Python 中使用 matplotlib plot 沿 x 轴旋转曲线? - How to plot the rotation of a curve along the x-axis with matplotlib in Python? 如何强制绘图在python中显示x轴值 - How to force the plot to show the x-axis values in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM