0

I wrote a simple code to start off with Joyplots on Matplotlib. Here's the entire code:

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()

I keep getting this error:

ValueError: `dataset` input should have multiple elements.

What does this mean, what am I doing wrong, and how do I fix this code?

Marcus Campbell
  • 2,746
  • 4
  • 22
  • 36
Abhishek
  • 553
  • 2
  • 9
  • 26

2 Answers2

0

You need to generate multiple records per year; your code generates single record per year.

I've updated your random number generation:

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

random.seed(4554)

randomlist = np.random.rand(1000)
randomyear = list(range(1999, 2019)) * 50

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

fig, axes = joypy.joyplot(df, by="Year", column="Values",figsize=(5,8))
ame
  • 446
  • 3
  • 5
  • Ah that might explain it. But be that as it may, the new code produces this error - `UserWarning: Matplotlib is currently using agg, which is a non-GUI backend, so cannot show the figure.` I tried researching this error and I tried using a solution pointed out on Stack itself but it isn't solving anything. What are backend errors? – Abhishek Mar 26 '19 at 15:21
  • 1
    I've not come across that error but found: https://stackoverflow.com/questions/37365357/when-i-use-matplotlib-in-jupyter-notebook-it-always-raise-matplotlib-is-curren . If you're running in jupyer try running `%matplotlib inline`. – ame Mar 26 '19 at 16:17
  • I've been staring at that exact post for the past thirty minutes. Doesn't help. It's for Ubuntu and one of the answers just states to remove fig.show() - which in no way helps me see what I've just made. Thank you for your help anyway! – Abhishek Mar 26 '19 at 16:19
  • 1
    Good luck figuring it out :) – ame Mar 26 '19 at 16:21
  • Interesting. I figured out a way to directly save the image using `plt.savefig()` without displaying it and sure enough that works. I'd still want to see the image though. Don't know what's going to resolve that. – Abhishek Mar 26 '19 at 16:36
0

I got the same error using the following code:

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

ValueError: `dataset` input should have multiple elements.

I checked my dataframe column "AC". This column was supposed to only include values AC1, AC2 and AC3.

But I noticed that I have

  • 100 rows of "AC1"
  • 103 rows of "AC2"
  • 99 rows of "AC3"
  • 1 row of "Other" (this should have been AC3)

I replaced "Other" with "AC3" so that no values in the "AC" column of my dataset appears only once. It fixed my problem.