我与seaborn工作,并试图让我的条形图条形图表更好看。在seaborn
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
x = ['One', 'Two', 'Three', 'Four', 'Five']
y = [2, 3, 0, 4.5, 4]
y2 = [0, 0, -5, 0, 0]
sns.axes_style('white')
sns.set_style('white')
b = sns.barplot(x,y,color='pink')
sns.barplot(x,y2, color='red')
for p in b.patches:
b.annotate(
s='{:.1f}'.format(p.get_height()),
xy=(p.get_x()+p.get_width()/2.,p.get_height()),
ha='center',va='center',
xytext=(0,10),
textcoords='offset points'
)
b.set_yticks([])
sns.despine(ax=b, left=True, bottom=True)
我竟拿出了标签栏的代码从堆栈溢出另一个线程。
我有即负杆被标记在正侧的问题。我也想在每张图的开始处摆脱零,并且可能将x = ['One','Two','Three','Four','Five']
移动到零的中间,而不是在底部。
我认为你的主要问题是你打电话给barplot两次。找到一种将它压缩到一个通话的方式可能会有很大的帮助。此外,请提供您用于通知此帖的问题的链接。 –
你应该尝试限制这只是一个问题。我现在回答最后一个:'sns.despine(ax = b,bottom = True,left = True)'将摆脱框架。 –
你得到的'0.0'的,因为你通过所有的补丁的循环,所以你需要包括不标注一个条件时,p.get_height的'值()'不大于零。 –