python-2.7 - 如何在 matplotlib 中重复调用 ylim()?
问题描述
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
。这可能吗??
解决方案
我认为不需要 for 循环。可能是我没有正确回答您的问题。为什么不先保存用户输入值,然后分配限制。您将不得不转换为浮动
# Store the user input in variables (as you are doing)
ymin=input("Enter Duration Min Limit : ")
ymax=input("Enter Duration Max Limit : ")
plt.ylim(ymin, ymax)
可能您必须float/int
根据您的数据类型将用户输入转换为。
推荐阅读
- python - 条形图的注释
- c# - 如何确保 Addin / xll 与 C# 以编程方式创建的 Excel 工作簿“打包”?
- laravel - 使用summernote时没有保存说明
- swiftui - 我可以在 swiftUI 中将一个数组放入另一个数组吗?
- grammar - 形式语法去除单元生产
- python-3.x - 计算置信区间 - Bootstap
- jenkins - 从 Jenkins 上传的 JRXML 提供 HTTP-500,但在其他地方也可以使用
- unity3d - 将颜色应用到具有材料颜色的文本
- drake - Pydrake:访问额外的 SNOPT 求解器输出 (iter)
- elasticsearch - Elasticsearch 内联字符串替换似乎什么都不做