Untitled
unknown
plain_text
a year ago
2.5 kB
9
Indexable
import matplotlib.pyplot as plt
import numpy as np
# Sample data
labels = ['Extraversion', 'Introversion', 'Openness', 'Neuroticism', 'Agreeableness', 'Conscientiousness']
# Reasons for listening to music (averaged ratings for each personality type)
mood_enhancement = [5, 3, 4, 2, 4, 3]
emotional_regulation = [2, 4, 3, 5, 3, 3]
social_bonding = [5, 2, 2, 1, 4, 2]
intellectual_stimulation = [1, 5, 5, 2, 3, 3]
background_music = [3, 4, 2, 3, 5, 5]
# Preferred genres (as percentages for each personality type)
preferred_genres = {
'Pop': [30, 10, 5, 15, 10, 40],
'Classical': [5, 25, 10, 0, 10, 10],
'Jazz': [5, 10, 30, 5, 5, 10],
'Hip-hop': [20, 5, 5, 15, 10, 0],
'EDM': [20, 5, 5, 10, 5, 0],
'Metal': [10, 0, 0, 30, 0, 0],
'Folk': [5, 10, 10, 5, 20, 5],
'Rock': [5, 10, 10, 15, 10, 20]
}
# Live vs Recorded music preference (averaged ratings)
live_music_preference = [5, 2, 4, 3, 3, 2]
recorded_music_preference = [3, 5, 4, 5, 4, 5]
# Creating bar chart for reasons for listening to music
fig, axs = plt.subplots(3, 1, figsize=(10, 18))
# Bar chart 1: Reasons for listening to music
x = np.arange(len(labels)) # the label locations
width = 0.15 # the width of the bars
axs[0].bar(x - 2*width, mood_enhancement, width, label='Mood Enhancement')
axs[0].bar(x - width, emotional_regulation, width, label='Emotional Regulation')
axs[0].bar(x, social_bonding, width, label='Social Bonding')
axs[0].bar(x + width, intellectual_stimulation, width, label='Intellectual Stimulation')
axs[0].bar(x + 2*width, background_music, width, label='Background Music')
axs[0].set_ylabel('Average Rating')
axs[0].set_title('Reasons for Listening to Music by Personality Type')
axs[0].set_xticks(x)
axs[0].set_xticklabels(labels)
axs[0].legend()
# Pie chart 2: Preferred genres
axs[1].set_title('Preferred Genres by Personality Type')
genre_slices = [sum(preferred_genres[genre]) for genre in preferred_genres]
axs[1].pie(genre_slices, labels=preferred_genres.keys(), autopct='%1.1f%%', startangle=90)
# Bar chart 3: Live vs Recorded Music Preference
axs[2].bar(x - width/2, live_music_preference, width, label='Live Music')
axs[2].bar(x + width/2, recorded_music_preference, width, label='Recorded Music')
axs[2].set_ylabel('Average Rating')
axs[2].set_title('Live vs. Recorded Music Preference by Personality Type')
axs[2].set_xticks(x)
axs[2].set_xticklabels(labels)
axs[2].legend()
plt.tight_layout()
plt.show()
Editor is loading...
Leave a Comment