在Python中绘制标记点。

huangapple go评论75阅读模式
英文:

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:

在Python中绘制标记点。

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:

在Python中绘制标记点。

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")

huangapple
  • 本文由 发表于 2023年5月18日 05:11:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/76276234.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定