[英]How to find trend line with high and low line?
我一直在使用依赖数据集。 我的数据集看起来像这样。
Date Open High Low Close Adj Close year_month
2019-04-15 1345.0 1348.949951 1335.000000 1340.150024 1332.769409 2019-04
2019-04-16 1345.0 1360.000000 1340.000000 1343.750000 1336.349609 2019-04
2019-04-18 1375.0 1389.750000 1365.000000 1385.949951 1378.317139 2019-04
2019-04-22 1360.0 1367.000000 1341.300049 1345.349976 1337.940796 2019-04
2019-04-23 1348.0 1373.000000 1346.000000 1363.849976 1356.338867 2019-04
这是我的代码,但如果我们看到图表,x 轴看起来很乱
f,ax1 = plt.subplots(figsize=(8, 5))
ax1.set_xlabel('Date')
ax1.set_ylabel('Price')
ax1.set_title('Original Plot')
ax1.plot('Date', 'Adj Close', data = df);
Output:-
所以我使用了另一个功能,但这个数字和以前不一样。
f,ax1 = plt.subplots(figsize=(15, 5))
ax1.set_xlabel('Date')
ax1.set_ylabel('Price')
ax1.set_title('Original Plot')
ax1.plot('year_month', 'Adj Close', data = df);
预期的 Output:- (注意:- 这只是一个例子。这个数字与我的数据集无关)
希望能尽快得到回应。 提前谢谢各位。
您的问题只是确定 x 轴上的刻度。 我创建了一个虚拟数据来证明我的观点。
这是设置xticks
之前图表的样子:
import pandas as pd
import matplotlib.pyplot as plt
df = pd.read_csv("test.csv")
f,ax1 = plt.subplots(figsize=(15, 5))
ax1.set_xlabel('Date')
ax1.set_ylabel('Price')
ax1.set_title('Original Plot')
ax1.plot('Date', 'Price', data = df)
这是设置xticks
后的图表; 您可以通过在plt.show()
之前编写以下两行来做到这一点
ax1.set_xticks(ax1.get_xticks()[::30])
plt.xticks(rotation=45)
希望这能回答你的问题!!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.