马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
from scipy import interpolate
import matplotlib.pyplot as plt
import numpy as np
x = np.array(['2020-07-15','2020-07-16','2020-07-17','2020-07-20','2020-07-21','2020-07-22','2020-07-23'])
y = np.array([17.58,20.05,18.17,18.66,18.81,20.44,20.24])
plt.xlabel("Date");
plt.ylabel("values")
plt.xticks(rotation=45)
plt.plot(x,y)
结果:
感觉很丑,现在想要绘制平滑曲线from scipy import interpolate
import matplotlib.pyplot as plt
import numpy as np
x = np.array(['2020-07-15','2020-07-16','2020-07-17','2020-07-20','2020-07-21','2020-07-22','2020-07-23'])
y = np.array([17.58,20.05,18.17,18.66,18.81,20.44,20.24])
xnew =np.arange(0,10,0.1)
func = interpolate.interp1d(x,y)
ynew = func(xnew)
plt.plot(xnew,ynew)
结果提示:
TypeError: Cannot cast array data from dtype('float64') to dtype('<U32') according to the rule 'safe'
请问 有办法解决吗,或者有别的方法去绘制平滑曲线,网上查了好久都是x轴和y轴都为数字 |