Multi line chart in plotly

I am trying to plot the following data in plotly as a multi line chart with the date series in x axis and sales figures of departments in y axis. I am using pandas dataframe to hold the data.

Date dept1 dept2 dept3
1/5/2018 5 3 0
2/5/2018 17 11 6
3/5/2018 24 21 15

dept_df = pd.read_csv(β€˜dept_sales.csv’)

Hi, you can use below code

final_cols = [col for col in list(df.columns) if col != 'Date']

data = [go.scatter(x = df['Date'],
                   y = df[col],
                   mode = 'lines',
                   name = col) for col in final_cols]
layout = go.Layout(
    title = 'Multiline chart'
)
fig = go.Figure(data=data,layout=layout)

where df is your dataframe

Thanks Abhinav. How do I skip two dates in the x axis while displaying the plots? Say 1/5/2018 4/5/2018 etc. Also while hovering on the plot, the dept name should be displayed along with the value.

Hi @June1,

you can create your own list based what you want to display on xaxis. then use tickvals in layout section to display the value. For example:

x_value_display = ['01-04-2016','03-04-2016','05-04-2016']

tickvals = x_value_display

inside layout section of x_axis.

use below link for example https://plotly.com/python/axes/