难住了。它们都是Numpy数组,它们都是相同的形状,所以为什么我得到" ValueError:x和y必须具有相同的第一维"
谢谢
func generateRandomNumber(min: Int, max: Int) -> Int {
let randomNum = Int(arc4random_uniform(UInt32(max) - UInt32(min)) + UInt32(min))
return randomNum
}
代码运行产生
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()
答案 0 :(得分:1)
来自文档:
plot_date(x, y, fmt='bo', tz=None, xdate=True,
ydate=False, **kwargs)
Similar to the plot() command, except the x or y (or both) data is considered to be dates, and the axis is labeled accordingly.
您的dates
是(31,),但2
是什么?为什么它不是一个有31个值的数组?
plt.plot_date(dates, np.arange(dates.shape[0]))
在上升线绘制一组点,x轴上有日期。