4

I want to plot the frequencies of a variable y by a variable x and to that effect I am using the seaborn.countplot() method. However I am getting an error message.

For a reproducible example see below:

surveys_species_by_plot_sample

    plot_id taxa
0   1   Bird
1   1   Rabbit
2   1   Rodent
3   2   Bird
4   2   Rabbit
5   2   Reptile
6   2   Rodent
7   3   Bird
8   3   Rabbit
9   3   Rodent

The intent now is to plot the number of taxa (Birds, Rabbits etc) by plot_id. I am using the following command:

sn.countplot(x = "plot_id", y = "taxa", data = surveys_species_by_plot_sample,
             palette = sn.color_palette(palette = ["SteelBlue" , "Salmon"], n_colors = 4))

I am getting the following error message:

TypeError: Cannot pass values for both `x` and `y`

I do not understand, since the documentation states that both x and y variables can be passed to the function:

Parameters: x, y, hue : names of variables in data or vector data, optional Inputs for plotting long-form data. See examples for interpretation.

data : DataFrame, array, or list of arrays, optional Dataset for plotting. If x and y are absent, this is interpreted as wide-form. Otherwise it is expected to be long-form.

Your advice will be appreciated.

2 Answers 2

3

Reading examples in the Documentation, you can only pass x or y, not both. Stating X or Y changes the orientation of your chart. You might need a different chart type.

Sign up to request clarification or add additional context in comments.

Comments

2

If you want to use both the x and y in your plot, you can't use countplot, instead you should use sn.barplot :)

sn.barplot(x = "plot_id", y = "taxa", data = surveys_species_by_plot_sample, palette = sn.color_palette(palette = ["SteelBlue" , "Salmon"], n_colors = 4))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.