【问题标题】:Seaborn/Matplotlib: how to remove the horizontal white lines that are overlaying the bars?Seaborn/Matplotlib:如何删除覆盖条形图的水平白线?
【发布时间】:2023-01-22 21:19:31
【问题描述】:

这是它的样子:

enter image description here

我想删除覆盖黑条的白线。顺便说一句:是否可以删除图例背后的背景?

`定义堆栈(): 数据 1 = [

    0.7,
    0.8,
    0.3,
    0.6,
    0.5

]

data2 = [

    20, 30, 23, 17, 28

]
sns.set_theme()
data = np.multiply(data1, 100)

r = [0, 1, 2, 3, 4]

fig, ax1 = plt.subplots()
ax1.bar(r, data, color="black", width=.5)
plt.ylim(0,100)
plt.ylabel('Percent')
plt.xlabel('Lineage')
ax2 = ax1.twinx()
ax2.bar(r, data2, color="red", width=.1)
plt.ylim(0,150)
plt.ylabel("Number")

lgnd1 = mpatches.Patch(color="black", label='Percent')
lgnd2 = mpatches.Patch(color="red", label='Number')
plt.legend(loc='upper center',
           bbox_to_anchor=(0.5, 1.2),
           ncol=3, handles=[lgnd1, lgnd2])

plt.savefig('number.svg', bbox_inches="tight", transparent=True)
plt.show()`

【问题讨论】:

    标签: matplotlib seaborn


    【解决方案1】:

    您可以使用以下代码:

    plt.grid(False)
    

    【讨论】:

      最近更新 更多