2014-12-20 69 views
1

这就是我迄今为止所做的。然而,我的问题是,我无法打印条形图的y轴上的值/比例?有任何想法吗?我还要添加哪些其他风格?如何在条形图的y轴上打印值/刻度

import seaborn as sb 
from matplotlib import pyplot 

%matplotlib inline 

sb.axes_style("white") 
sb.set_style("ticks") 
sb.set_context("talk") 

x1 = np.array(['U', 'G']) 
x2 = np.array(['H', 'W']) 

f, (ax1, ax2) = pyplot.subplots(1, 2, figsize=(12, 6)) 

y1 = np.array([831824, 3306662]) 
y2 = np.array([1798043, 1508619]) 

sb.barplot(x1, y1, ci=None, palette="Blues", hline=.0001, ax=ax1) 
sb.barplot(x1, y2, ci=None, palette="Reds", hline=.0001, ax=ax2) 

ax1.set_ylabel("Occurences") 
ax1.set_xlabel("Totals") 

ax2.set_ylabel("Occurences") 
ax2.set_xlabel("Types") 

sb.despine(bottom=True) 
pyplot.setp(f.axes, yticks=[]) 
pyplot.tight_layout(h_pad=3) 

sb.despine() 

enter image description here

回答

2

基于@约翰 - cipponeri的回答是:

使用使用pyplot.*只在最后打开轴操作称为轴运行,你的情况ax2,这是正确的阴谋功能。使用轴实例在需要的地方生效。这一个替换代码的巡演的最后一块,我希望它对应于你的预期情节:

ax1.grid(axis='y', linestyle='-') 
ax2.grid(axis='y', linestyle='-') 
pyplot.tight_layout(h_pad=3) 
sb.despine() 
1

你可以试试线条样式。

pyplot.grid(axis='y', linestyle='-') 
+0

感谢,但它不工作:( – user706838

+0

pyplot.setp(f.axes,yticks = [])你将yticks设置为一个空数组,它是否不包含你的y轴的值? –

+0

太棒了,它可以工作,但只能在右边的subplot上。这是什么原因? – user706838

相关问题