Group by the category and plot each line individually.
(按类别分组并分别绘制每条线。)
import numpy as np
import matplotlib.pyplot as plt
def cat_horizontal_plot(data, category, numeric, ax=None):
ax = ax or plt.gca()
for cat, num in data.groupby(category):
ax.plot(np.sort(num[numeric].values), [cat]*len(num),
marker="o", mec="k", mfc="none", linestyle="-", color="k")
ax.set_xlabel(numeric)
ax.set_ylabel(category)
ax.margins(y=0.4)
ax.figure.tight_layout()
Use it as
(用作)
import seaborn as sns
tips = sns.load_dataset('tips')
cat_horizontal_plot(tips, "sex", "tip")
plt.show()
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…