plotly.py icon indicating copy to clipboard operation
plotly.py copied to clipboard

Violin plot with 'name' attribute set as Datetime get's flattened out

Open benmaxmartin opened this issue 4 years ago • 0 comments

I'm trying to make a horizontally oriented ridge plot . Following is the code plotly.version == 5.3.1

Ridgeline plot

base_date = dt.datetime.strptime(start_date,'%Y-%m-%d')
fig = go.Figure()

for day in range(days) :
                    offset = dt.timedelta(days=day)
                    date = (base_date + offset).strftime('%Y-%m-%d')
                    violin_plot_data = swData[date]
                    fig.add_trace(go.Violin(x = violin_plot_data.loc[:,metric_name] , 
                                                    orientation = 'h',
                                                    width = 3 ,
                                                    side = 'positive',
                                                    meanline_visible=True,
                                                    points = False
                                                   )
                                         )
    
fig.show()

I'm getting the following output :

newplot (1)

However I wish to set "name" attribute for individual dates . I did the following

Ridgelin plot

base_date = dt.datetime.strptime(start_date,'%Y-%m-%d')
fig = go.Figure()

for day in range(days) :
    offset = dt.timedelta(days=day)
    date = (base_date + offset).strftime('%Y-%m-%d')
    violin_plot_data = swData[date]
    fig.add_trace(go.Violin(x = violin_plot_data.loc[:,metric_name] , 
                                    orientation = 'h',
                                    width = 3 ,
                                    side = 'positive',
                                    name = date,
                                    meanline_visible=True,
                                    points = False
                                   )
                         )
fig.show()

The output that I'm getting is

newplot (2)

Kindly clarify if it's a bug in the framework or a silly mistake from my side . TY :)

EDIT : I've found a work around and answered it here [https://stackoverflow.com/a/69894008/6571670] but I feel Plotly should be able to parse dates explicitly

benmaxmartin avatar Nov 09 '21 06:11 benmaxmartin