We need to draw PDF curves of energy consumption under three weather conditions. The first one is using seaborn method. The second way is to try to draw the same curve by datascience and matplotlib. Firstly, why are the starting points inconsistent and how should I solve them? Secondly, do I have any problems when calculating kde? The relationships and shapes of the curves are not quite the same.
First: seaborn
sns.displot(data, x="Power", hue="Weather", kind="kde")
plt.xlabel('Daily PV generation [kW]', fontsize=14)
plt.ylabel('PDF', fontsize=14)
datascience+matplotlib
#将每种天气对应的数据提取出来
data1_sunny=data1.where("Weather",'Sunny').sort('Power')
data1_rainy=data1.where('Weather','Rainy').sort('Power')
data1_cloudy=data1.where("Weather",'Cloudy').sort('Power')
#引入scipy(计算PDF用),这个matplotlib为啥一定要输这个命令?不然就报错
import scipy.stats as st
%matplotlib inline
#分别计算每种天气对应的PDF,并赋值给对应x,y
PS=data1_sunny.column('Power')
PR=data1_rainy.column('Power')
PC=data1_cloudy.column('Power')
PDF1=st.gaussian_kde(PS)
PDF2=st.gaussian_kde(PR)
PDF3=st.gaussian_kde(PC)
x1=PS
x2=PR
x3=PC
y1=PDF1
y2=PDF2
y3=PDF3
#绘图啦!
plt.plot(x1,PDF1.pdf(x1),label='Sunny',color='orange')
plt.plot(x2,PDF2.pdf(x2),label='Rainy',color='deepskyblue')
plt.plot(x3,PDF3.pdf(x3),label='Cloudy',color='green')
plt.axis('tight')
plt.legend(loc='upper right')
plt.title("PV curve")
plt.xlabel('Daily PV generation [kW]')
plt.ylabel('PDF')
plt.show()
0 Answer
No answer yet
这家伙很懒,什么都没留下...