问题描述
我正在尝试使用pandas plotting创建一个带有seaborn导入的堆叠水平条形图。我想删除栏之间的空格,但也没有栏重叠。这就是我尝试过的:
I am trying to use pandas plotting to create a stacked horizontal barplot with a seaborn import. I would like to remove space between the bars, but also not have the bars overlap. This is what I've tried:
import pandas as pd
import numpy as pd
import seaborn as sns
df = pd.DataFrame(np.random.rand(15, 3))
df.plot.barh(stacked=True, width=1)
这似乎没有导入seaborn,虽然我喜欢seaborn风格,它通常是我工作的ipython笔记本中的导入这可能吗?
This seems to work without importing seaborn, though I like the seaborn style and it is usually an import in the ipython notebook I am working in is this possible?
推荐答案
如果将条形线宽设置为seaborn样式,则使用matplotlib默认值也可以看到此工件:
This artifact is also visible with matplotlib defaults if you set the bar linewidth to what seaborn style has:
import pandas as pd
import numpy as np
df = pd.DataFrame(np.random.rand(15, 3))
df.plot(stacked=True, width=1, kind="barh", lw=.5)
一个解决方案是将条线增加到matplotlib默认值的大致位置:
A solution would be to increase the bar lines back to roughly where the matplotlib defaults are:
import pandas as pd
import numpy as np
import seaborn as sns
df = pd.DataFrame(np.random.rand(15, 3))
df.plot(stacked=True, width=1, kind="barh", lw=1)
这篇关于使用seaborn和大 pandas 密谋防止重叠的酒吧的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!