I am using python and plotly in order to design a bar plot for the mean rating of certain categories in the data set I am using. I got the bar chart nearly how I want it however I would like to change the color for each specific bar in the plot but can't seem to find a clear way on how to do this online.
Data Set
from pandas import Timestamp
pd.DataFrame({'id': {0: 1, 1: 2, 2: 3, 3: 4, 4: 5},
'overall_rating': {0: 5, 1: 4, 2: 5, 3: 5, 4: 4},
'user_name': {0: 'member1365952',
1: 'member465943',
2: 'member665924',
3: 'member865886',
4: 'member1065873'},
'date': {0: Timestamp('2022-02-03 00:00:00'),
1: Timestamp('2022-02-03 00:00:00'),
2: Timestamp('2022-02-02 00:00:00'),
3: Timestamp('2022-02-01 00:00:00'),
4: Timestamp('2022-02-01 00:00:00')},
'comments': {0: 'Great campus. Library is always helpful. Sport course has been brill despite Civid challenges.',
1: 'Average facilities and student Union. Great careers support.',
2: 'Brilliant university, very social place with great unions.',
3: 'Overall it was very good and the tables and chairs for discussion sessions worked very well',
4: 'Uni is nice and most of the staff are amazing. Facilities (particularly the library) could be better'},
'campus_facilities_rating': {0: 5, 1: 3, 2: 5, 3: 4, 4: 4},
'clubs_societies_rating': {0: 5, 1: 3, 2: 4, 3: 4, 4: 4},
'students_union_rating': {0: 4, 1: 3, 2: 5, 3: 5, 4: 5},
'careers_service_rating': {0: 5, 1: 5, 2: 5, 3: 5, 4: 3},
'wifi_rating': {0: 5, 1: 5, 2: 5, 3: 5, 4: 3}})
Code Used
# Plot to find mean rating for different categories
fig = px.bar(df, y=[df.campus_facilities_rating.mean(), df.clubs_societies_rating.mean(),
df.students_union_rating.mean(), df.careers_service_rating.mean(), df.wifi_rating.mean()],
x=['Campus Facilities', 'Clubs & Societies', 'Students Union', 'Careers & Services', 'Wifi'],
labels={
"y": "Mean Rating (1-5)",
"x": "Category"},
title="Mean Rating For Different Student Categories")
fig.show()
UPDATED ATTEMPT
# Plot to find mean rating for different categories
fig = px.bar(df, y=[df.campus_facilities_rating.mean(), df.clubs_societies_rating.mean(),
df.students_union_rating.mean(), df.careers_service_rating.mean(), df.wifi_rating.mean()],
x=['Campus Facilities', 'Clubs & Societies', 'Students Union', 'Careers & Services', 'Wifi'],
labels={
"y": "Mean Rating (1-5)",
"x": "Category"},
title="Mean Rating For Different Student Categories At The University of Lincoln",
color_discrete_map = {
'Campus Facilities' : 'red',
'Clubs & Societies' : 'blue',
'Students Union' : 'pink',
'Careers & Services' : 'grey',
'Wifi' : 'orange'})
fig.update_layout(barmode = 'group')
fig.show()
Output just gives all bars as blue.