英文:
ploting markers in python
问题
I am using pandas, and filling a data frame with some data... I want to plot the data in a graph and plot markers on it (signals).
I have this code:
data_frame.set_index('timestamp', inplace=True) # set Datetime column as index
plt.plot(data_frame['close'])
plt.plot(data_frame['long'].index, data_frame['close'], '^', markersize=2, color='g')
plt.plot(data_frame['short'].index, data_frame['close'], '^', markersize=2, color='r')
plt.show()
data_frame['long']
and data_frame['short']
are bool values (True or False), data_frame['close']
is close price (float).
The result:
Plotting is happening even if data_frame['long']/data_frame['short']
is false.
英文:
i am using pandas, and filling a data frame with some data... i want to plot the data in a graph and plot markers on it (signals)
i have this code:
data_frame.set_index('timestamp', inplace=True) # set Datetime column as index
plt.plot(data_frame['close'])
plt.plot(data_frame['long'].index, data_frame['close'], '^', markersize=2, color='g')
plt.plot(data_frame['short'].index, data_frame['close'], '^', markersize=2, color='r')
plt.show()
data_frame['long']
and data_frame['short']
are bool values (True or False), data_frame['close']
is close price (float)
the result:
Ploting is happening even if data_frame['long']/data_frame['short']
is false
答案1
得分: 1
你可以循环遍历数据并检查数据是否为真或假:
for idx in data_frame["long"].index.tolist():
if data_frame.loc[idx]["long"]:
plt.plot(idx, data_frame.loc[idx]["close"], "^", markersize=5, color="g")
英文:
You can loop thru data and check if the data is true or false:
for idx in data_frame["long"].index.tolist():
if data_frame.loc[idx]["long"]:
plt.plot(idx, data_frame.loc[idx]["close"], "^", markersize=5, color="g")
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论