Stumped. sie sind beide Numpy Arrays sie beide die gleiche Form sind also warum bin ich immer „Valueerror: x und y müssen gleiche erste Dimension haben“Numpy-Arrays mit gleicher Form, aber mit ValueError: x und y müssen dieselbe erste Dimension haben
dank
import matplotlib.pyplot as plt
import numpy as np
from datetime import datetime
num_of_days = 31
dates = np.empty(num_of_days)
ranks = np.empty(dates.shape[0])
ranks.fill(50) # test data all 50's
dates = np.arange('2016-01', num_of_days , dtype='datetime64[D]')
print("ranks shape", ranks.shape)
print("dates shape", dates.shape)
print("ranks type", type(ranks))
print("dates type", type(dates))
print("dates shape first dimension",dates.shape[0])
print(dates)
print(ranks)
plt.plot_date(dates,2)
plt.plot(dates,ranks)
plt.show()
Der Code Lauf Ausbeuten
Python 3.5.1 (v3.5.1:37a07cee5969, Dec 6 2015, 01:38:48) [MSC v.1900 32 bit (Intel)] on win32
Type "copyright", "credits" or "license()" for more information.
>>>
===== RESTART: E:\scanned\als course\12 15 14 the al project\dev code\8 29 16 test plots.py =====
ranks shape (31,)
dates shape (31,)
ranks type <class 'numpy.ndarray'>
dates type <class 'numpy.ndarray'>
dates shape first dimension 31
['2016-01-01' '2016-01-02' '2016-01-03' '2016-01-04' '2016-01-05'
'2016-01-06' '2016-01-07' '2016-01-08' '2016-01-09' '2016-01-10'
'2016-01-11' '2016-01-12' '2016-01-13' '2016-01-14' '2016-01-15'
'2016-01-16' '2016-01-17' '2016-01-18' '2016-01-19' '2016-01-20'
'2016-01-21' '2016-01-22' '2016-01-23' '2016-01-24' '2016-01-25'
'2016-01-26' '2016-01-27' '2016-01-28' '2016-01-29' '2016-01-30'
'2016-01-31']
[ 50. 50. 50. 50. 50. 50. 50. 50. 50. 50. 50. 50. 50. 50. 50.
50. 50. 50. 50. 50. 50. 50. 50. 50. 50. 50. 50. 50. 50. 50.
50.]
Traceback (most recent call last):
File "E:\scanned\als course\12 15 14 the al project\dev code\8 29 16 test plots.py", line 23, in <module>
plt.plot_date(dates,2)
File "C:\Users\dave\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\pyplot.py", line 3173, in plot_date
data=data, **kwargs)
File "C:\Users\dave\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\__init__.py", line 1812, in inner
return func(ax, *args, **kwargs)
File "C:\Users\dave\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\axes\_axes.py", line 1494, in plot_date
ret = self.plot(x, y, fmt, **kwargs)
File "C:\Users\dave\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\__init__.py", line 1812, in inner
return func(ax, *args, **kwargs)
File "C:\Users\dave\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\axes\_axes.py", line 1424, in plot
for line in self._get_lines(*args, **kwargs):
File "C:\Users\dave\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\axes\_base.py", line 386, in _grab_next_args
for seg in self._plot_args(remaining, kwargs):
File "C:\Users\dave\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\axes\_base.py", line 364, in _plot_args
x, y = self._xy_from_xy(x, y)
File "C:\Users\dave\AppData\Local\Programs\Python\Python35-32\lib\site-packages\matplotlib\axes\_base.py", line 223, in _xy_from_xy
raise ValueError("x and y must have same first dimension")
ValueError: x and y must have same first dimension
>>>
Für alle, die sich wundern, ist der Fehler kein Python-Fehler, sondern ein Matplotlib-Fehler (Ich habe die letzten drei Zeilen nicht getestet, aber es gibt keinen Fehler vorher). – Benjamin
Lassen Sie uns nicht in der Schwebe. Zeigen Sie die Drucke. Ein Teil des Fehler-Tracebacks kann hilfreich sein, auch wenn der Fehler im Aufruf "Plot" stark verschachtelt ist. Zwei dieser Eingänge stimmen nicht in ihrer Form überein. – hpaulj
Bitte beachten Sie die bearbeitete Frage für die Run-Ausgabe. Tut mir leid, dass ich nicht daran gedacht habe, es einzuschließen – theakson