为什么matplotlib上的此Joyplot代码显示此错误?

时间:2019-03-26 14:59:55

标签: python pandas matplotlib

我写了一个简单的代码,从Matplotlib上的Joyplots开始。这是完整的代码-

import random
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt import joypy

random.seed(4554)

randomlist = random.sample(range(100,10000),1000) 
randomyear = np.linspace(1018,2018,num=1001)

df=pd.DataFrame(list(zip(randomyear,randomlist)),columns=['Year','Values'])

fig, axes = joypy.joyplot(df, by="Year", column="Values",figsize=(5,8))

plt.show()

我不断收到此错误-

ValueError: `dataset` input should have multiple elements.

这是什么意思,我在做什么错,以及如何解决此代码?

2 个答案:

答案 0 :(得分:0)

您每年需要生成多个记录;您的代码每年生成一条记录。

我已经更新了您的随机数生成:

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="items-collection">
<div class="col-md-4 items car-col-responsive">
                                 <div data-toggle="buttons" class="btn-group">
                                    <label class="btn">
                                       <div class="vehicle-item">
                                          <input type="checkbox" name="multi[]">
                                          <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 50 23" width="82%" height="100%" fill="#707D86">
                                          <g>
                                             <circle cx="37.5" cy="15.8" r="2.6"/>
                                             <circle cx="7.9" cy="15.9" r="2.7"/>
                                             <path d="M41.7,16.5c0,0,4.6,1.4,5.7-1.1c0,0,1.1-3.4-0.5-4.2l-0.1-1L45.6,10c0,0,0.9-1.9,0.2-2l-4.1-0.7L33.7,4c0,0-8.1-1.3-11.2,0c0,0-5.5,1.9-8.2,4.1c0,0-9.6,0.4-10.6,1.8c0,0-3.3,3.1-2.5,5c0,0,0.4,1.6,2,2.1H4c0,0-0.2-4.7,4.4-4.3c0,0,0,0,0.1,0c0.4,0,3.7,0.2,3.7,4.8h21.1c0,0,0.3-4.9,3.8-4.9C37.1,12.4,41.2,11.6,41.7,16.5z"/>
                                             <path d="M37.5,8.1h-9.7V4.5c0,0,6,0.1,6.7,0.6C34.6,5.1,36.8,6.3,37.5,8.1z" fill="#FFFDFD"/>
                                             <path d="M25.8,4.4v3.6h-7.5C18.3,8.1,21.4,3.9,25.8,4.4z" fill="#FFFDFD"/>
                                          </g>
                                          <path d="M4.2,10.1l0.6,0.9l-2,2.3l-1.5,0.5C1.3,13.7,2.5,10.2,4.2,10.1z" fill="#FFFDFD"/>
                                          </svg>
                                          <h5 class="vehicle-item-title">Saloon</h5>
                                       </div>
                                    </label>
                                 </div>
                              </div>
                          <!-- SUVs -->
                          <div class="items col-md-4 car-col-responsive">
                             <div data-toggle="buttons" class="btn-group">
                                <label class="btn">
                                   <div class="vehicle-item">
                                      <input type="checkbox" name="multi[]">
                                      <svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 53 23" width="87%" height="100%" fill="#707D86">
                                      <g>
                                         <path d="M37.8,20.6H15.7l-1-0.8c0,0,0-4.5-3.5-4.4c0,0-4-0.6-4.1,4.2c0,0,0.2,1.2-1.4,1c0,0-1.8-0.3-2.5-1.6L2,17.4c0,0-0.6-2,0.6-2.5c0,0-1.5-2.1,2.5-3.3c0,0,3.7-1.6,5.8-1.3l11-5.8c0,0,15.3-2.2,23.7,0c0,0,3.7,1.9,4.6,7.6c0,0,0.4,5.8,0,7c0,0-0.7,1.5-1,1.6c0,0-1.1,0.7-2.2,0c0,0-0.5-5.4-4.8-5.1C42.3,15.5,38.1,14.9,37.8,20.6z"/>
                                         <path d="M41.8,7.2v4.5h4C45.8,11.7,45.4,8.3,41.8,7.2z" fill="#FFFFFF"/>
                                         <path d="M31.1,6.4L29.9,11l9.2,0.2c0,0,1.3-4.3-1.4-4.8H31.1z" fill="#FFFFFF"/>
                                         <path d="M27.8,6.4l-0.5,4.8l-8.5,0.1c0,0-1.1-1.7,0.6-2.9l4-1.8L27.8,6.4z" fill="#FFFFFF"/>
                                         <circle cx="41.8" cy="20" r="3" fill="#707D86"/>
                                         <circle cx="10.7" cy="19.4" r="3" fill="#707D86"/>
                                         <path d="M5,12.2c0,0-3.7,0.9-2.5,3.3s3.2-0.7,3.2-0.7"/ fill="#FFFFFF">
                                      </g>
                                      </svg>
                                     <h5 class="vehicle-item-title">SUVs</h5>
                                   </div>
                                </label>
                             </div>
                          </div>
                            </div>

答案 1 :(得分:0)

使用以下代码出现相同的错误:

fig, axes = joypy.joyplot(data_sub[["AC","B"]], by="AC", column="B")

ValueError: `dataset` input should have multiple elements.

我检查了数据框列“ AC”。假定此列仅包含值AC1,AC2和AC3。

但是我注意到我有

  • 100行“ AC1”
  • 103行“ AC2”
  • 99行“ AC3”
  • 1行“其他”(应该是AC3)

我用“ AC3”替换了“其他”,因此数据集“ AC”列中的值仅出现一次。它解决了我的问题。