Home > Software engineering >  Change color of candle stick graph in python Plotly
Change color of candle stick graph in python Plotly

Time:01-17

I have a candle stick graph created to show monthly candles of a stock using plotly in python. I want to customize only one candle for April 2022 (see figure). Here is the complete code.

        fig = make_subplots(rows=1, cols=1, subplot_titles=[], \
                        specs=[[{"secondary_y": True}]], \
                        vertical_spacing=0, shared_xaxes=True, row_width=[1.0])
        fig.add_trace(go.Scatter(x=df.index, y=df['Pivot'], marker=dict(color='black'), line=dict( width=2),
                         mode='lines', name='Pivot Point'), row=1, col=1)

        fig.add_trace(go.Scatter(x=df.index, y=df['R1'], marker=dict(color='olive'), line=dict( width=1,dash='dot'),
                         mode='lines', name='Resistance 1'), row=1, col=1)


        fig.add_trace(go.Scatter(x=df.index, y=df['S1'], marker=dict(color='turquoise'), line=dict( width=2,dash='dot'),
                         mode='lines', name='Support 1'), row=1, col=1)


# Adding Candlestick graph
        fig.add_trace(go.Candlestick(x=df.index,
                                 open=df['Open'],
                                 close=df['Close'],
                                 low=df['Low'],
                                 high=df['High'],
                                 increasing_line_color='green', decreasing_line_color='red', name='HRC Price'),row=1, col=1,)
    

    
    fig.update_layout(
    title='HRC Monthly Price',
    yaxis_title='Price',
    shapes = [dict(
        x0='2022-03-14', x1='2022-03-14', y0=0, y1=1, xref='x', yref='paper',
        line_width=2)],
    annotations=[dict(
        x='2022-03-14', y=0.05, xref='x', yref='paper',
        showarrow=False, xanchor='left', text='Ukraine - Russia War Starts')]
)
    


    return fig

enter image description here

  • Related