如何使用seaborn或matplotlib将barplot中的条的中间顶部与一条线连接?

时间:2020-04-11 02:24:41

标签: matplotlib seaborn

myDict = {'a':[3,13,18,16,19,9,13,15,0,2],\
      'b':[23,14,18,24,19,9,14,13,21,22],\
      'c':[38,17,12,15,39,38,23,19,16,16]}

df = pd.DataFrame(myDict) df_melted = df.melt(value_vars = ['a','b','c'])

fig,ax1 = plt.subplots() sns.barplot(x ='variable',y ='value',data = df_melted,capsize = 0.1,ax = ax1,order = ['b','a','c']) 请 plt.show() plt.close()

1 个答案:

答案 0 :(得分:0)

使用lineplot,但是首先,您需要保持相同的顺序,因为lineplot的{​​{1}}参数不像order。这些步骤是:

  1. 创建数据框的副本
  2. barplot设置为variable的{​​{1}}
  3. 同一把斧头上的线图

代码为:

order

这将产生:

enter image description here