想要绘制x_values_edited和速度。我有这个错误:
ValueError:使用序列设置数组元素
plt.plot(x_values_edited, speed, '.' )
我的代码和输入在这里:
x_values_Edited:
[datetime.datetime(2015,1,1,0,0),datetime.datetime(2015,1,1,0,1),datetime.datetime(2015,1,1,0,2),datetime .datetime(2015,1,1,0,3),datetime.datetime(2015,1,1,0,4),datetime.datetime(2015,1,1,0,5),datetime.datetime(2015, 1,1,0,6),datetime.datetime(2015,1,1,0,7),datetime.datetime(2015,
速度
[[58.5,97.0,56.0,87.5,95.0,100.0,104.0,98.5,101.0,98.5,86.5,90.0,97.5,16.5,103.0,98.0,48.0,98.5,93.5,99.0,101.5,86.5,108.5 ,22.0,92.5,84.5,103.5,86.5,103.0,96.5,91.5,101.5,86.0],[99.5,101.0,96.5,94.5,92.0,89.5,83.0,94.0,97.5,103.5,93.5,101.0,95.5,89.0 ,102.5,89.0,104.5,1010.0,107.0,96.5,97.5,97.5,93.0,95.0,88.5,89.0,101.0,97.0,98.5,]]
答案 0 :(得分:0)
这是一个工作示例。我必须产生时间,因为你还没有在你的问题中包含完整的输入:
from matplotlib.pyplot import plot, show
from datetime import datetime, timedelta
def date_range(stop, start, step=1):
"""
Time generator
:param stop: Stop time
:type stop: Start time
:param start: Steps based upon which the time is to be calculated.
:type start: datetime.datetime()
:param step: datetime.datetime()
:type step: int, float
"""
delta_date = stop - start
numerator = 0
while numerator < delta_date.seconds:
yield start + timedelta(0, numerator)
numerator += step
speed = [
58.5, 97.0, 56.0, 87.5, 95.0, 100.0, 104.0,
98.5, 101.0, 98.5, 86.5, 90.0, 97.5, 16.5,
103.0, 98.0, 48.0, 98.5, 93.5, 99.0, 101.5,
86.5, 108.5, 22.0, 92.5, 84.5, 103.5, 86.5,
103.0, 96.5, 91.5, 101.5, 86.0
]
speed_len = len(speed)
# Hypothetical start time
date_start = datetime(2014, 3, 15, 0)
# and finish time
date_end = datetime(2014, 3, 15, 0, int(speed_len/60), speed_len%60)
# Generate a time list: 1 second per item in |speed|
x_values_edited = [val for val in date_range(stop=date_end, start=date_start, step=1)]
# Scatter plot
plot(x_values_edited, speed, '.')
# Display the plot
show()
显示:
答案 1 :(得分:0)
这是一个快速修复。
来自matplotlib.pyplot import scatter,show,xlim,ylim
from matplotlib.pyplot import scatter, show, xlim, ylim
for index, item in enumerate(speed):
scatter([times[index]]*len(item), item, marker='.')
xlim(min(times), max(times))
ylim(min(min(speed)), max(max(speed)))
show()
产地:
对不起,花了很长时间。我不得不在地下做!