-1

i have all the data i need to plot in a single row e.g.:

mcc_name    year_1  year_2  year_3  year_1_%    year_2_%    year_3_%
book shop   30000   1500.41 9006.77 NaN         -0.4708        -0.60379

i want the x axis to be the values in columns: [year_1, year_2, year_3] and values in y axis to be the y - axis (pct change)... and the size of the bubble proportional to the values in [year_1, year_2, year_3] .

sns.scatterplot(data=data_row , x=['year_1', 'year_2', 'year_3'], y=['year_1_%', 'year_2_%', 'year_3_%'], size="pop", legend=False, sizes=(20, 2000))

# show the graph
plt.show()

but i get this error:

ValueError: Length of list vectors must match length of `data` when both are used, but `data` has length 1 and the vector passed to `y` has length 3.

how can i plot??

Maths12
  • 852
  • 3
  • 17
  • 31

1 Answers1

0

You need to have your data in long format:

import pandas as pd
import seaborn as sns
import numpy as np

df = pd.DataFrame(np.array([30000,1500.41,9006.77,np.NaN,-0.4708,-0.60379]).reshape(1,-1),
                  columns = ['year_1','year_2','year_3','year_1_%','year_2_%','year_3_%'],
                  index = ['mcc_name'])

Usually you can use wide_to_long if your columns are formatted properly, but in this case, maybe easily to melt separately and join:

values = df.filter(regex='year_[0-9]$', axis=1).melt(value_name="value",var_name="year")
perc = df.filter(regex='_%', axis=1).melt(value_name="perc",var_name="year")
perc.year = perc.year.str.replace("_%","")
sns.scatterplot(data=values.merge(perc,on="year"),x = "year", y = "perc", size = "value")

enter image description here

StupidWolf
  • 45,075
  • 17
  • 40
  • 72