【问题标题】:All arguments should have the same length. The length of argument `y` is 6, whereas the length of previous arguments ['year'] is 100所有参数都应具有相同的长度。参数 `y` 的长度是 6,而前面的参数 ['year'] 的长度是 100
【发布时间】:2021-09-13 06:00:45
【问题描述】:

我使用的库

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

【问题讨论】:

  • 我不熟悉这个库,但大多数人所做的只是通过压缩等长的列表来绘制笛卡尔坐标以获得每个点的位置。您需要做的是提取每个声音特征的值列,然后将其作为y 传递,而不是将标签列表作为y 传递。

标签: python arguments linegraph plotly-express graph-data-science


【解决方案1】:

让我们试试这个方法

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)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-06-17
    • 2021-12-05
    • 2019-05-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-12
    • 2017-06-22
    相关资源
    最近更新 更多