Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/295.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
将字符串数组转换为matplotlib的datetimes python_Python_Arrays_Datetime_Matplotlib - Fatal编程技术网

将字符串数组转换为matplotlib的datetimes python

将字符串数组转换为matplotlib的datetimes python,python,arrays,datetime,matplotlib,Python,Arrays,Datetime,Matplotlib,我试图使用for循环将times_中的时间字符串数组从_text_文件数组转换为datetimes,然后我想根据另一个名为temperature的数组绘制这些datetimes,打印false并返回temperature数组的值。只有当温度数组中的所有值都相同时,才会不打印任何内容(仅打印true)。我遇到的问题是将times_中的所有字符串时间从_text_文件数组转换为datetimes,这会导致下面的错误 def values_equal_np_array(temp, time_creat

我试图使用for循环将times_中的时间字符串数组从_text_文件数组转换为datetimes,然后我想根据另一个名为temperature的数组绘制这些datetimes,打印false并返回temperature数组的值。只有当温度数组中的所有值都相同时,才会不打印任何内容(仅打印true)。我遇到的问题是将times_中的所有字符串时间从_text_文件数组转换为datetimes,这会导致下面的错误

def values_equal_np_array(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')

        plt.xlabel('Time')
        plt.ylabel('Temperature')
        plt.title('Time vs Temperature')        

        #specifying the beginning to end interval of temperature collection
        final_times = times_from_text_file[time_created_index:`time_modified_index]                  

        for i in range(len(final_times)):
            new_time = datetime.datetime.strptime(final_times, "%H:%M")
            datetimes.append(new_time)
            new_array[i] = new_time

        final_times = matplotlib.dates.date2num(new_time)
        matplotlib.pyplot.plot_date(new_array, temp)
        plt.show()

        #the values that appear in the non-uniform temperature array on display      
        return np.unique(temp)

#testing the function 
values_equal_np_array([1, 1, 1, 2, 3, 4], 3, 8, ['10:15','12:31','12:32','1:33', '12:34', '1:35', '2:36', '2:37', '3:38', '1:39'])

False

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
<ipython-input-11-6151e84dc0c7> in <module>()
----> 1 values_equal_np_array([1, 1, 1, 2, 3, 4], 3, 8, ['10:15','12:31','12:32','1:33', '12:34', '1:35', '2:36', '2:37', '3:38', '1:39'])

<ipython-input-10-96555d9f1618> in values_equal_np_array(temp, time_created_index, time_modified_index, times_from_text_file)
     15 
     16         for i in range(len(final_times)):
---> 17             new_time = datetime.datetime.strptime(final_times, "%H:%M")
     18             datetimes.append(new_time)
     19             new_array[i] = new_time

TypeError: strptime() argument 1 must be str, not list
def values_equal_np_数组(临时、创建索引的时间、修改索引的时间、文本文件中的时间):
如果(len(np.unique(temp))=1:
返回真值
其他:
#告诉用户在指定的时间间隔内温度不相等
打印('False')
plt.xlabel(“时间”)
plt.ylabel(“温度”)
plt.title(‘时间与温度’)
#指定温度采集的开始到结束间隔
final_times=来自_text_文件的时间[time_created_index:`time_modified_index]
对于范围内的i(len(最终_次)):
新的\u时间=datetime.datetime.strtime(最后的\u时间,“%H:%M”)
datetimes.append(新时间)
新_数组[i]=新_时间
最终时间=matplotlib.dates.date2num(新时间)
matplotlib.pyplot.plot\u日期(新数组,临时)
plt.show()
#显示在非均匀温度阵列中的值
返回np.unique(临时)
#测试功能
值等于np数组([1,1,1,2,3,4],3,8,['10:15','12:31','12:32','1:33','12:34','1:35','2:36','2:37','3:38','1:39']))
假的
---------------------------------------------------------------------------
TypeError回溯(最近一次调用上次)
在()
---->1值等于np数组([1,1,1,2,3,4],3,8,['10:15','12:31','12:32','1:33','12:34','1:35','2:36','2:37','3:38','1:39'])
在值数组中(临时、创建索引的时间、修改索引的时间、文本文件中的时间)
15
16对于范围内的i(len(最终_次)):
--->17新的\u时间=datetime.datetime.strtime(最后的\u时间,“%H:%M”)
18日期时间。追加(新时间)
19新_数组[i]=新_时间
TypeError:strTime()参数1必须是str,而不是list
使用:

使用:

new_times = [datetime.datetime.strptime(x, "%H:%M") for x in final_times]