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
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)
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.
This question already has answers here:
How to plot multiple pandas columns
(3 answers)
Use index in pandas to plot data
(6 answers)
Closed 1 year ago.
I am trying to make an area plot. However the x axis of the graph shows 1,2,3 rather than the year. How can I change this? I saw some related questions here, however the code there is a bit too complicated for me.
My code is:
import matplotlib as mpl
import matplotlib.pyplot as plt
areaplot=r'data.xlsx'
df_areaplot = pd.read_excel(areaplot)
df_areaplot.plot(kind='area')
plt.title('SDG Spending Trend')
plt.ylabel('Amount Spent')
plt.xlabel('Years')
plt.show()
As #tmdavison points out in the comment, you can use column names to determine axes, even with specified lists of columns, i.e.:
df_areaplot.plot(kind='area',
x='BDG',
y=['Citizen Initiatives',
'Education and Employability',
'Enviromental Sustainability',
'Woman Empowerment'])
This question already has answers here:
Pandas bar plot -- specify bar color by column
(2 answers)
vary the color of each bar in bargraph using particular value
(3 answers)
Closed 2 years ago.
I was trying the tutorial posted on http://queirozf.com/entries/pandas-dataframe-plot-examples-with-matplotlib-pyplot
and was wondering whether it was possible to have a bar chart created that could have colored columns.
import pandas as pd
import matplotlib.pyplot as plt
df = pd.DataFrame({
'name':['john','mary','peter','jeff','bill','lisa','jose'],
'age':[23,78,22,19,45,33,20],
'gender':['M','F','M','M','M','F','M'],
'state':['california','dc','california','dc','california','texas','texas'],
'num_children':[2,0,0,3,2,1,4],
'num_pets':[5,1,0,5,2,2,3]
})
df.plot(kind='bar',x='name',y='age')
the current code above creates
.
However, I would like to have the eventual output showing that the columns have a different
.
(The column showing John would be red, Mary would be orange and so on)
Any and all help is appreciated! Thank you.
Specify the colors:
df.plot(kind='bar',x='name',y='age',
color=["red","blue","green","yellow","black","grey","purple"])
to get
You might want to remove the the legend using
df.plot(kind='bar',x='name',y='age',
color=["red","blue","green","yellow","black","grey","purple"],
legend=False)
as it only displays one color.