Python Pandas - 用 Seaborn 绘制小提琴图、明确的顺序并将观察显示为棍子
Seaborn 中的 Violin Plot 用于绘制箱线图和核密度估计的组合。用于此。使用带有值stick的内部参数,观察结果显示为一根棍子。seaborn.violinplot()
假设以下是 CSV 文件形式的数据集 - Cricketers.csv
首先,导入所需的库 -
import seaborn as sbimport pandas as pd
importmatplotlib.pyplotas plt
将 CSV 文件中的数据加载到 Pandas DataFrame 中 -
dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\Cricketers.csv")
与 Academy 和 Age 一起绘制小提琴情节。通过传递明确的命令来控制命令,即基于“学院”的排序。观察结果显示为使用带有值棒的内部参数的棒 -
sb.violinplot(x = 'Academy', y = "Age", order=["Western Australia", "Tasmania","South Australia"],data = dataFrame, inner="stick")
示例
以下是代码 -
import seaborn as sb输出结果import pandas as pd
importmatplotlib.pyplotas plt
# Load data from a CSV file into a Pandas DataFrame:
dataFrame = pd.read_csv("C:\\Users\\amit_\\Desktop\\Cricketers.csv")
# plotting violin plot with Academy and Age
# Control order by passing an explicit order i.e. ordering on the basis of "Academy"
# observations show as a stick using the inner parameter with value stick
sb.violinplot(x = 'Academy', y = "Age", order=["Western Australia", "Tasmania","South Australia"],data = dataFrame, inner="stick")
# display
plt.show()
这将产生以下输出 -
以上是 Python Pandas - 用 Seaborn 绘制小提琴图、明确的顺序并将观察显示为棍子 的全部内容, 来源链接: utcz.com/z/363218.html