Error: : barplot() takes from 0 to 1 positional arguments but 2 positional arguments (and 1 keyword-only argument) were given

Plot up the distribution of counts

sns.barplot(class_counts.values, class_counts.index, color=‘b’)
plt.title(‘Distribution of Classes for Training Dataset’, fontsize=15)
plt.xlabel(‘Number of Patients’, fontsize=15)
plt.ylabel(‘Diseases’, fontsize=15)

Hi @Mahmoud_Menessy,

I am not sure to which exercise this code snippet refers to, but I will try to help out.
Seaborn barplot expects to specify explicitly the x= and y=. Are you sure that the x is class_counts.values and the y is class_counts.index? Or are they keys and values?


Hi @Mahmoud_Menessy ,

Try this,
sns.barplot(x=class_counts.values, y=class_counts.index, color='b') plt.title('Distribution of Classes for Training Dataset', fontsize=15) plt.xlabel('Number of Patients', fontsize=15) plt.ylabel('Diseases', fontsize=15)

  • x=class_counts.values represents the data for the x-axis (the counts of each class),
  • y=class_counts.index represents the data for the y-axis (the names of each class),
  • color='b' sets the color of the bars in the plot to blue.

Also, make sure that class_counts is a pandas Series where the index is the name of the classes (or ‘Diseases’ in your case) and the values are the counts of each class (or ‘Number of Patients’ in your case).