I figured out how to convert my list of datetimes into string using a technique slightly different than what was presented on stackoverflow, but now I would like to plot the array datetimes_final that I appended to when I converted my string to datetimes from the final_times array, but I keep getting the error ValueError: x and y must have same first dimension, when my final_times and temp array do have the same number of elements in order to be plotted so I do not understand why I am getting this error, and need help fixing it. I also posted the error I am getting but I did not post the entire error since it's over 200 lines so I just posted the important part.
def values_equal_np_array3(temp, time_created_index, time_modified_index, times_from_text_file):
if (len(np.unique(temp)) == 1):
return True
else:
#tells user the temps are not equal for a specified interval of time
print ('False')
#specifying the beginning to end interval of temperature collection
final_times = times_from_text_file[time_created_index: time_modified_index]
#create a new empty list to hold datetimes
datetimes_final = []
#iterate over the empyty list
for element in final_times:
datetime_conversion = datetime.datetime.strptime(element, "%H:%M")
datetimes_final.append(datetime_conversion)
plt.xlabel('Time')
plt.ylabel('Temperature')
plt.title('Time vs Temperature')
#http://stackoverflow.com/questions/1574088/plotting-time-in-python-with-matplotlib
#I am trying to plot two arrays-one in datetimes and another in ints- using the link above
final_times = matplotlib.dates.date2num(datetimes_final)
matplotlib.pyplot.plot_date(final_times, temp)
#the values that appear in the non-uniform temperature array on display as an array
return np.unique(temp)
#test case for the values_equal_np_array3 function
#the first 6 times from the times_from_text_file array should be plotted against the temp array
values_equal_np_array3(np.array([1, 1, 1, 2, 3, 4]), 0, 5, np.array(['10:15','12:31','12:32','1:33', '12:34', '1:35', '2:36', '2:37', '3:38', '1:39']))
False
ValueError Traceback (most recent call last)
<ipython-input-79-c16b47f0901d> in <module>()
----> 1 values_equal_np_array3(np.array([1, 1, 1, 2, 3, 4]), 0, 5, np.array(['10:15','12:31','12:32','1:33', '12:34', '1:35', '2:36', '2:37', '3:38', '1:39']))
<ipython-input-78-67671c2f9e11> in values_equal_np_array3(temp, time_created_index, time_modified_index, times_from_text_file)
23
24 final_times = matplotlib.dates.date2num(datetimes_final)
---> 25 matplotlib.pyplot.plot_date(final_times, temp)
26
27
C:\Users\mintw\Anaconda3\lib\site-packages\matplotlib\axes\_base.py in _xy_from_xy(self, x, y)
217 y = _check_1d(y)
218 if x.shape[0] != y.shape[0]:
--> 219 raise ValueError("x and y must have same first dimension")
220 if x.ndim > 2 or y.ndim > 2:
221 raise ValueError("x and y can be no greater than 2-D")
ValueError: x and y must have same first dimension