我想要展示一个人们年龄的小提琴情节,每个都属于0级或1级。我创建了一个年龄列表,以及一个与班级对应的单独列表。我可以为单个列表绘制小提琴图,但是如何绘制1级和0级分离的年龄分布?
import numpy as np
import seaborn as sns
import csv
import matplotlib.pyplot as plt
reader = csv.reader(file)
ages = []
class = []
#Here we populate our list with data from our csv
for column in reader:
ages.append(column[3])
class.append(column[0])
#Here we can initialize Figure and Axes object
fig, ax = plt.subplots()
#Here we create our violin plot for the age distribution
ax.violinplot(ages, vert=False)
#
# Here we need to add code to plot age distribution seperated by class
#
#Here we show our violin plot
plt.show()