Seaborn with multiple Columns [duplicate] - python

This question already has answers here:
Plotting two columns of dataFrame in seaborn
(1 answer)
Seaborn multiple barplots
(2 answers)
seaborn multiple variables group bar plot
(1 answer)
Closed 12 months ago.
I have a dataframe data_gender:
gender
math_score
reading_score
writing_score
avg_score
female
63.63
72.61
72.47
69.57
male
68.73
65.47
63.31
65.84
and I want to make a seaborn barplot that looks like this plot that I made with matplotlib with simple line
data_gender.plot.bar(figsize=(8,6))
How would one do it with seaborn?

You can reshape with melt and pass the data to sns.barplot:
sns.barplot(data=data_gender.melt(id_vars='gender',
value_name='score', var_name='course'),
x='gender', y='score', hue='course')
output:

sns.barplot(x='gender', y='score', hue='course', data=data_gender)

Related

create stacked plot of percentages [duplicate]

This question already has answers here:
Stacked bar chart in Seaborn
(2 answers)
How to make a horizontal stacked histplot based on counts?
(2 answers)
Closed 25 days ago.
I have a dataframe containing the percentage of people in my dataset stratified per Gender and Age.
df_test = pd.DataFrame(data=[['Male','16-24',10],
['Male','25-34',5],
['Male','35-44',2],
['Female','16-24',3],
['Female','25-34',60],
['Female','35-444',20],
],
columns=['Gender','Age','Percentage'])
First I create a plot showig the percentages of Male and Female in the dataset
df_test.groupby('Gender').sum().plot(kind='bar',rot=45)
Now I would like to add within each bar the percentage of people in the age ranges in a stacked kind of way...
Could you help ?
You can use the cumsum() method for cumulative summation as
df_test.groupby('Age').sum().cumsum().plot(kind="bar",rot=45)

stripplot and box plot from dataframe in python [duplicate]

This question already has answers here:
seaborn boxplot and stripplot points aren't aligned over the x-axis by hue
(1 answer)
Seaborn boxplot + stripplot: duplicate legend
(2 answers)
How to do a boxplot with individual data points using seaborn
(1 answer)
How to overlay data points on seaborn figure-level boxplots
(2 answers)
Closed 7 months ago.
I'm trying to make a box plot and a strip plot from the following dataframe, but I think I'm not putting the arguments or maybe the df should be re-arranged but I don't know how.
the dataframe is here
I'm hopping to have a strip plot and a box for each color (column) in the same plot.
I'd be grateful if you could help

Displaying KDE plots in a grid format using Seaborn [duplicate]

This question already has answers here:
How to make seperate Seaborn kdeplots for all different columns from the same pandas Dataframe?
(2 answers)
How to Plot a Matrix of Seaborn Distplots for All Columns in the Dataframe
(3 answers)
Plot multiple columns of pandas DataFrame using Seaborn
(2 answers)
Closed 10 months ago.
I am using the Wisconsin Breast Cancer dataset for a class project and I am attempting to display 10 KDE plots in 5 x 2 layout. Unfortunately,the plots are displayed in scrollable window which is definitely not what I would like.
features = ['radius_mean', 'texture_mean', 'perimeter_mean', 'area_mean', 'smoothness_mean', 'compactness_mean', 'concavity_mean', 'concave_points_mean', 'symmetry_mean', fractal_dimension_mean']
for feature in features:
df[feature].plot.kde(title=feature)
plt.show()
Any help would be appreciated.
Thank you.

how can I remove legend from the figure in seaborn? [duplicate]

This question already has answers here:
Avoiding repeated legend in seaborn boxplot overlaid by swarmplot
(1 answer)
Seaborn boxplot + stripplot: duplicate legend
(2 answers)
Closed 10 months ago.
Here is my diagrams,
I want to remove the labels of the second bar that is C1,C2,C3,C4,C5, because it is repeating.

Plotting a multicolored scatter graph from a pandas data frame [duplicate]

This question already has answers here:
plot different color for different categorical levels using matplotlib
(8 answers)
Scatter plots in Pandas/Pyplot: How to plot by category [duplicate]
(8 answers)
Seaborn scatter plot from pandas dataframe colours based on third column
(1 answer)
Closed 1 year ago.
I have a pandas dataframe called data, with two numerical columns (col1 and col2) and one categorical (col3)
I want to plot col1 and col2 against each other, but colour points by col3
I tried this:
plt.scatter(data["col1"],data["col2"],c=data["col3"])
which I expected to work but got an error.

Categories

Resources