【发布时间】:2019-09-07 14:50:09
【问题描述】:
我正在生成一个多条形图作为水平条形图,我现在需要做的是在特定位置的每个水平条中注释(基本上创建一条垂直线)(基于x轴值)对于每个 y 轴,其中 y 轴是分类(名称),x 轴是数字(整数)s。
我查看了axis.vlines,但无法正常工作。
import seaborn as sns
import matplotlib.pyplot as plt
crashes = sns.load_dataset("car_crashes").sort_values("total", ascending=False)
crashes['max_range'] = crashes['total'] * 0.85
sns.set_color_codes("muted")
sns.set(style="whitegrid")
sns.barplot(x="total", y="abbrev", data=crashes, label="", color="r")
sns.barplot(x="max_range", y="abbrev", data=crashes, label="", color="y")
sns.barplot(x="alcohol", y="abbrev", data=crashes,label="normal range", color="g")
#dummy data for the "vertical lines" i want to plot
crashes['actual'] = crashes['alcohol'] * 1.85
上面的代码创建了一个这样的图:
https://seaborn.pydata.org/examples/horizontal_barplot.html
现在我基本上想从底层数据框的另一列在绘图的每一行(因此对于绘图中的每个条形图)添加一条垂直线。
【问题讨论】: