
我第一次使用 matplotlib 并嘗試學習資料幀。
現在,在我的代碼中,我有兩個串列。我為這兩個串列分別創建了一個資料框。我打算使用這些串列創建一個階梯圖。
energy_price = [33.28, 30.00, 29.15, 28.49, 34.66, 50.01, #14 sept nord pool day ahead SE1
71.52, 77.94, 81.97, 87.90, 92.76, 94.98,
92.31, 90.03, 90.09, 87.44, 85.37, 79.97,
79.92, 77.83, 76.28, 65.06, 53.07, 34.16]
rtn_t0=15
price_energy = []
for price in energy_price:
price_energy = price_energy [int(price)] * int(60 / rtn_t0) #prices for 96 time slots
time1 = list()
for x in range(1,int(num_t 1)):
time1.append(x)
df = pd.DataFrame(price_energy)
df = pd.DataFrame(time1)
如何在 x 軸上使用 time1 和在 y 軸上創建 price_energy 的階梯圖?
任何幫助,將不勝感激。
uj5u.com熱心網友回復:
步驟圖
uj5u.com熱心網友回復:
在您的代碼中,您分配df了兩次,第二次覆寫第一次。正確的方法應該是:
import pandas as pd
df = pd.DataFrame({'time1': time1,
'price_energy': price_energy})
然后繪制階梯圖:
import matplotlib.pyplot as plt
plt.step(x='time1', y='price_energy', data=df)
plt.show()
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/522658.html
