Hey all,
I am trying to fill the area between 2 lines that are crossing at a random point.
Iāve tried adding multiple traces and different fill options but I canāt figure out how to achive the below result.
Thank you,
Alex
Hey all,
I am trying to fill the area between 2 lines that are crossing at a random point.
Iāve tried adding multiple traces and different fill options but I canāt figure out how to achive the below result.
Thank you,
Alex
Hi. I think if you are using pandas you can get the portion of data for each crossing point and then fill the area for each portion. Then, append all the fill individual areas in one graph. I know is not the best solution but, it could be a good start.
Hi, thank you for the fast reply. If was very helpful.
I managed to achive what I was looking for. See below:
What I did I create a 3rd line ā-------ā (āsenkou_cā). I calculated the line below like that.
df['senkou_c'] = np.nan
for index, row in df.iterrows():
if row['senkou_a'] < row['senkou_b']:
df.at[index,'senkou_c'] = row['senkou_a']
elif row['senkou_a'] > row['senkou_b']:
df.at[index,'senkou_c'] = row['senkou_b']
elif row['senkou_a'] == row['senkou_b']:
df.at[index,'senkou_c'] = row['senkou_b']
And then I plotted the like below:
if self.df.__contains__('senkou_c'):
trace = go.Scatter(
x = self.df['date'],
y = self.df['senkou_c'],
name = "------",
line = dict(color = ('rgba(255, 255, 255, 0)')))
self.data.append(trace)
if self.df.__contains__('senkou_b'):
trace = go.Scatter(
x = self.df['date'],
y = self.df['senkou_b'],
fill = 'tonexty',
name = "Senkou B",
fillcolor = 'rgba(255, 0, 0, 0.3)',
line = dict(color = ('rgba(255, 0, 0, 0.3)')))
self.data.append(trace)
if self.df.__contains__('senkou_c'):
trace = go.Scatter(
x = self.df['date'],
y = self.df['senkou_c'],
name = "------",
line = dict(color = ('rgba(255, 255, 255, 0)')))
self.data.append(trace)
if self.df.__contains__('senkou_a'):
trace = go.Scatter(
x = self.df['date'],
y = self.df['senkou_a'],
fill = 'tonexty',
name = "Senkou A",
fillcolor = 'rgba(0, 255, 0, 0.3)',
line = dict(color = ('rgba(0, 255, 0, 0.3)')))
self.data.append(trace)
I hope this will help other people looking for something similar.
Thank you,
Alex
Alex, thank you. I was having problems shading the positive and negative areas of Ichimoku clouds and of ADX DI+/DI- of OHLC+V data.
I was expecting being able to choose a fill color based on a conditional, i.e, fillcolor = np.where(condition, color A, color B), but alas this isnāt possible.
It would be fantastic if the PlotLy developers inplemented this ability since itās of tremendous use in quantitative finance, econometrics, technical analysis, and i suspect for much more.
markers have this ablity. but them cant fill an area. :_)
Hi @bin1482, welcome to the forums.
I think itās going to be almost impossible to help you without your data.
@AIMPED ļ¼after checking the dataļ¼figured out when line A equals to line Bļ¼i gave C the value of np.nan, that caused the weird problem. Now everything is ok, thx for ur reply.
Could you post the code that worked for you please?