2
matplotlib를 사용하여 두 개의 목록을 그래프로 표시하려고했지만 x 및 y 치수와 관련하여 오류가 발생했습니다. 목록 중 하나에 날짜와 다른 숫자가 포함되어 있으면 목록의 내용을 볼 수 있습니다. 아래에 인쇄했습니다.matplotlib 오류 : ValueError : x와 y의 첫 번째 치수가 같아야합니다.
저는 len()으로 목록의 길이를 검사 해 보았습니다. 그래서 그들은 같아 보였으므로 조금 손실되었습니다. 나는 많은 실수없이이 오류에 대해 여러 개의 theads를 확인했습니다.
참고 : "query"에는 단순화를 위해 포함시키지 않은 SQL 쿼리가 포함되어 있습니다. 내 스크립트 내 코드 #####
t = 0
for row in query:
data = query[t]
date.append(data[0])
close.append(data[1])
t = t + 1
print "date = ", date
print "close = ", close
print "date length = ", len(date)
print "close length = ", len(close)
def plot2():
plt.plot(date, close)
plt.show()
plot2()
#
출력 : 사전에
date = [datetime.datetime(2010, 1, 31, 22, 0), datetime.datetime(2010, 1, 31, 22, 1), datetime.datetime(2010, 1, 31, 22, 2), datetime.datetime(2010, 1, 31, 22, 3), datetime.datetime(2010, 1, 31, 22, 4), datetime.datetime(2010, 1, 31, 22, 5), datetime.datetime(2010, 1, 31, 22, 6), datetime.datetime(2010, 1, 31, 22, 7), datetime.datetime(2010, 1, 31, 22, 8), datetime.datetime(2010, 1, 31, 22, 9), datetime.datetime(2010, 1, 31, 22, 10)]
close = [1.5945, 1.5946, 1.59465, 1.59505, 1.59525, 1.59425, 1.5938, 1.59425, 1.59425, 1.5939, 1.5939]
date length = 11
close length = 11
Traceback (most recent call last):
File "script.py", line 234, in <module>
plot2()
File "script.py", line 231, in plot2
plt.plot(date, close)
File "/usr/lib/pymodules/python2.7/matplotlib/pyplot.py", line 2467, in plot
ret = ax.plot(*args, **kwargs)
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 3893, in plot
for line in self._get_lines(*args, **kwargs):
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 322, in _grab_next_args
for seg in self._plot_args(remaining, kwargs):
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 300, in _plot_args
x, y = self._xy_from_xy(x, y)
File "/usr/lib/pymodules/python2.7/matplotlib/axes.py", line 240, in _xy_from_xy
raise ValueError("x and y must have same first dimension")
ValueError: x and y must have same first dimension
감사합니다.
좋은 아이디어! 그렇게함으로써 matplotlib이 어떤 이유로 든리스트 이름을 좋아하지 않는다는 것을 알았습니다. 나는 그것을 변경 시켰고 그것은 정상적으로 작동합니다. 도와 주셔서 정말로 고맙습니다. – user1582821