【发布时间】:2019-01-25 04:57:09
【问题描述】:
ylim() 这里的输入是使用 std_input 给出的。我在 Python 2.7 上。
df = pd.read_csv('sy_1_Mlogi_01081081_1.csv')
df.rename( columns={'Unnamed: 0':'time'}, inplace=True )
df['time'] = pd.to_datetime(df['time'])
df['Time'] = df['time'].dt.time
df['date'] = df['time'].dt.date
df = df.set_index(['date'])
a = input('starting_Date : ')
b = input('ending_Date : ')
starting_date = datetime.strptime(a, "%Y-%m-%d").date()
ending_date = datetime.strptime(b, "%Y-%m-%d").date()
df = df.loc[starting_date:ending_date]
x = df['Time']
y = df['d']
fig, ax = plt.subplots()
ax.plot_date(x, y)
long_title = 'Cycling {} to {} \n'
plt.title(long_title.format(starting_date,ending_date))
plt.legend()
plt.ylabel('duration')
plt.ylim(ymax=input("Enter Duration Max Limit : "))
plt.ylim(ymin=input("Enter Duration Min Limit : "))
plt.xlabel('Time')
fig.autofmt_xdate()
plt.show()
这里如何将ylim() 放入loop,这样我就不必一次又一次地运行程序。只需输入ylim 值,我就可以获得plot。这可能吗??
【问题讨论】:
标签: python-2.7 pandas matplotlib