Matplotlib 如何在条形图的y轴上打印值/比例
这就是我到目前为止所做的。然而,我的问题是,我不能在条形图的y轴上打印值/比例?有什么想法吗?我还可以添加哪些其他样式Matplotlib 如何在条形图的y轴上打印值/比例,matplotlib,seaborn,Matplotlib,Seaborn,这就是我到目前为止所做的。然而,我的问题是,我不能在条形图的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'
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()
您可以尝试线条样式
pyplot.grid(axis='y', linestyle='-')
根据@john cipponeri的回答: 使用在轴上运行的函数,称为使用
pyplot.
仅在上次打开的轴上运行,在您的情况下,ax2,它是正确的绘图。使用axis实例在需要的位置使其生效。将代码的最后一块替换为这一块,我希望它与预期的绘图对应:
ax1.grid(axis='y', linestyle='-')
ax2.grid(axis='y', linestyle='-')
pyplot.tight_layout(h_pad=3)
sb.despine()
setp(f.axes,yticks=[])如果将yticks设置为空数组,它不应该包含y轴的值吗?太棒了,它可以工作,但只在右侧子图上。原因是什么?