我遇到了使用matplotlib绘图和使用填充图类型的问题。我附上了我的plt.fill的样子。我从包含第一列中的日期时间的数据框创建了图,然后在下一列中计算了值。如果需要,我很乐意发布样本数据,但我想展示我的情节发生了什么......看起来非常奇怪,它填充低于0(除非我在这里遗漏了一些东西)然后最后它将所有东西都移到了沿对角线。
非常感谢任何帮助!
import pandas as pd
import numpy as np
import os as os
import matplotlib as mpl
import matplotlib.pyplot as plt
import datetime as dt
#set working path
working_path = '/Users/Earth/desktop/mydata'
os.chdir(working_path)
# name csv files to variables
chilled_water_supply = 'chilled_water_supply1.csv'
chilled_water_return = 'chilled_water_return1.csv'
chilled_water_flow = 'CofK_CW_Flow.csv'
#read correct date time format from csv file
datetimeparse1 = lambda x: pd.datetime.strptime(x, '%m/%d/%Y %H:%M')
#import chilled water temperautres and flow
df_chwsup = pd.read_csv(chilled_water_supply, parse_dates = ['Date_Time'], date_parser = datetimeparse1)
df_chwret = pd.read_csv(chilled_water_return, parse_dates = ['Date_Time'], date_parser = datetimeparse1)
df_chwflow = pd.read_csv(chilled_water_flow, parse_dates = ['Date_Time'], date_parser = datetimeparse1)
#set start date time and length of period
startdate = dt.datetime(2015,7,14,11,41,0)
numintervals = (14*24*60)
#create data frame with index of row numbers and correct date time period
df_datetime = pd.DataFrame(pd.date_range(startdate ,periods = numintervals, freq = "1min"), columns = ["Date_Time"])
#creating master data frame with outputs
df_mstr1 = pd.merge(df_datetime, df_chwsup, how = 'left', left_on = 'Date_Time', right_on = 'Date_Time')
df_mstr2 = pd.merge(df_mstr1, df_chwret, how = 'left', left_on = 'Date_Time', right_on = 'Date_Time')
df_mstr3 = pd.merge(df_mstr2, df_chwflow, how= 'left', left_on = 'Date_Time', right_on = 'Date_Time')
df_mstr3['tons'] = 500*(1/12000)*df_mstr3['flow_gpm']*(df_mstr2['chwr_temp_F'] - df_mstr1['chws_temp_F'])
#plot cooling tons over date time period
x1 = df_mstr3['Date_Time']
y1 = df_mstr3['tons']
plt.Line2D(x1,y1)
plt.xlim(dt.datetime(2015,7,14), dt.datetime(2015,7,28))
plt.ylim(-100,300)
plt.show()
答案 0 :(得分:0)
也许尝试使用pandas API for matplotlib:
df.index = df.date_time
df['tons'].plot(kind='area')