2

Library that I used

import numpy as np
import pandas as pd
import seaborn as sns
import plotly.express as px 
import matplotlib.pyplot as plt

Dataset https://i.stack.imgur.com/k4hIL.png

My Code

sound_features = ['acousticness', 'danceability', 'energy', 'instrumentalness', 'liveness', 'valence']
fig = px.line(year_data, x='year', y=sound_features)
fig.show()

My Output https://i.stack.imgur.com/iF529.png

Ideal Output https://i.stack.imgur.com/Fwsop.png

Shadic Mersal
  • 128
  • 1
  • 2
  • 8
  • I am not familiar with the library, but what most do is just plotting cartesian coordinates by zipping lists of equal length to get the position of each point. What you need to do is extract the column of values for each sound feature and then pass that as `y`, instead of giving a list of labels as `y`. – RookieHere Jul 01 '21 at 07:03

1 Answers1

2

let's try this way

plot_data = [
    go.Scatter(
        x=year_data['year'],
        y=year_data['acousticness'],
        name = 'acousticness'
    ),
    go.Scatter(
        x=year_data['year'],
        y=year_data['danceability'],
        name = 'danceability'
    ),
    go.Scatter(
        x=year_data['year'],
        y=year_data['energy'],
        name = 'energy'
    ),
    go.Scatter(
        x=year_data['year'],
        y=year_data['instrumentalness'],
        name = 'instrumentalness'
    ),
    go.Scatter(
        x=year_data['year'],
        y=year_data['liveness'],
        name = 'liveness'
    ),
    go.Scatter(
        x=year_data['year'],
        y=year_data['valence'],
        name = 'valence'
    )
]

plot_layout = go.Layout(
        xaxis={"type": "category"},
        title='Sound features'
    )
fig = go.Figure(data=plot_data, layout=plot_layout)
pyoff.iplot(fig)