x 축의 시간과 y 축의 정수 데이터를 원하므로 그래프를 그리려고합니다. 다음과 같은 오류가 발생합니다.
TypeError : float () 인수는 문자열 또는 숫자 여야합니다.
plt.plot(time,data)
위의 명령에서 오류 시간이 15:46:00 ~ 16:45:00 간격의 1 분마다 데이터 포인트를 포함하고 있음을 보여줍니다. 데이터 유형도 확인했으며 시간에 대한 datetime도 표시하고 있습니다.
import matplotlib as plt
import matplotlib
import datetime as db
import matplotlib.pyplot as plt
time=["16:45:00","16:46:00","16:47:00","16:48:00","16:49:00","16:50:00"]
data=[1,2,1,3,4,6]
time1=[]
for tr in time:
t=db.datetime.strptime(tr,"%H:%M:%S").time()
time1.append(t)
plt.plot(time1,data)
plt.show()
에서 제거해야 .time()
합니다.datetime.strptime
time = ["16:45:00", "16:46:00", "16:47:00", "16:48:00", "16:49:00", "16:50:00"]
data = [1, 2, 1, 3, 4, 6]
time1 = []
for tr in time:
t = db.datetime.strptime(tr, "%H:%M:%S")
time1.append(t)
fig,ax = plt.subplots()
ax.plot(time1, data)
plt.gcf().autofmt_xdate() formats the x-axis to get rotate the tick labels
plt.show()
이것은 그림을 생성합니다.
그러나 이것은 datetimes 끝에 추가 0을 제공합니다. 이를 제거하려면 datetimes의 형식을 지정해야합니다. 이는 matplotlibs DateFormatter 를 사용하여 수행 할 수 있습니다 .
from matplotlib.dates import DateFormatter
time = ["16:45:00", "16:46:00", "16:47:00", "16:48:00", "16:49:00", "16:50:00"]
data = [1, 2, 1, 3, 4, 6]
time1 = []
for tr in time:
t = db.datetime.strptime(tr, "%H:%M:%S")
time1.append(t)
#format the plotting of the datetime to avoid times like 12:45:00.00000000
date_formatter = DateFormatter('%H.%M.%S')
fig,ax = plt.subplots()
ax.plot(time1, data)
ax.xaxis.set_major_formatter(date_formatter)
plt.gcf().autofmt_xdate()
plt.show()
이것은 멋진 모습을 만듭니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다