利用python实现小提琴图的代码

import seaborn as sns
import matplotlib.pyplot as plt

# 加载seaborn内置的鸢尾花数据集
iris = sns.load_dataset("iris")

# 设置绘图风格,可选,这里使用默认风格
# sns.set_style("whitegrid")

# 绘制小提琴图,以'species'为分类依据,绘制'sepal_length'特征的小提琴图
# 可以根据实际需求更改x和y对应的列名来绘制不同变量的小提琴图
ax = sns.violinplot(x="species", y="sepal_length", data=iris)

# 设置图形标题
plt.title("Violin Plot of Sepal Length by Iris Species")

# 设置x轴标签
plt.xlabel("Iris Species")

# 设置y轴标签
plt.ylabel("Sepal Length")

# 展示图形
plt.show()

你可能感兴趣的:(可视化,python,开发语言)