Search code examples
plotlyopacitycandlestick-chart

Custom opacity Plotly candlesticks


I would like to know if we can change the opacity of the candlesticks so that they are the same color as the edges ?

like that

not like that


Solution

  • import plotly.graph_objects as go
    
    import pandas as pd
    from datetime import datetime
    
    df = pd.read_csv(
        "https://raw.githubusercontent.com/plotly/datasets/master/finance-charts-apple.csv"
    )
    df = df.head(8)
    fig = go.Figure(
        data=[
            go.Candlestick(
                x=df["Date"],
                open=df["AAPL.Open"],
                high=df["AAPL.High"],
                low=df["AAPL.Low"],
                close=df["AAPL.Close"],
            )
        ]
    )
    
    
    fig.update_xaxes(rangebreaks=[{"pattern": "day of week", "bounds": [6, 1]}])
    
    fig.update_traces(
        {
            d: {"fillcolor": c, "line": {"color": c}}
            for d, c in zip(["increasing", "decreasing"], ["red", "green"])
        }
    )
    

    enter image description here