所有参数应具有相同的长度。参数 `y` 的长度是 6,而之前的参数 ['year'] 的长度是 100

问题描述 投票:0回答:1

我使用过的图书馆

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

数据集 https://i.stack.imgur.com/k4hIL.png

我的代码

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

我的输出 https://i.stack.imgur.com/iF529.png

理想输出 https://i.stack.imgur.com/Fwsop.png

python arguments linegraph plotly-express
1个回答
2
投票

我们试试这个方法吧

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)
© www.soinside.com 2019 - 2024. All rights reserved.