orientation ='horizo​​ntal'用于排列的散射直方图

时间:2018-04-09 10:54:14

标签: matplotlib histogram orientation scatter

基于在线示例,我正在制作带有X和Y轴直方图的散点图。我希望这些直方图是线条,而不是条形图。对于X轴,这工作正常,但对于Y轴,我遇到的问题是我无法将方向设置为“水平”。 代码的第一部分与在线示例几乎相同:

left, width = 0.1, 0.5
bottom, height = 0.1, 0.5
bottom_h = left_h = left+width+0.01

rect_scatter = [left, bottom, width, height]
rect_histx = [left, bottom_h, width, 0.1]
rect_histy = [left_h, bottom, 0.1, height]

plt.figure(1, figsize=(10,10))
axScatter = plt.axes(rect_scatter)
axHistx = plt.axes(rect_histx)
axHistx.xaxis.set_major_formatter(NullFormatter())
axHistx.xaxis.set_minor_formatter(NullFormatter())
axHisty = plt.axes(rect_histy)
axHisty.yaxis.set_major_formatter(NullFormatter())
axHisty.yaxis.set_minor_formatter(NullFormatter())

axHistx.xaxis.set_major_locator( MultipleLocator(10) )
axHistx.xaxis.set_minor_locator( MultipleLocator(10) )
axHisty.yaxis.set_major_locator( MultipleLocator(10) )
axHisty.yaxis.set_minor_locator( MultipleLocator(10) )

# the scatter plot:
axScatter.scatter(PX, PY, edgecolors='none',s=5, label = 'Present')
axScatter.scatter(FX, FY, edgecolors='none',s=5, label = 'Future')

# now determine nice limits by hand:
binwidthx = 0.2
binwidthy = 1
xymax = np.max( [np.max(np.fabs(PX)), np.max(np.fabs(PY))] )
lim = ( int(xymax/binwidthx) + 1) * binwidthx

axScatter.set_xlim( (0, 20) )
axScatter.set_ylim( (0, 90) )

binsx = np.arange(0, lim + binwidthx, binwidthx)
binsy = np.arange(0, lim + binwidthy, binwidthy)

然后我按照以下方式制作组织图:

#histograms
gaus1 = stats.gaussian_kde(PX)
n1,x1 = np.histogram(PX, bins=binsx) 
axHistx.plot(x1,gaus1(x1),color = 'slateblue',label = 'Present', linewidth = .5)

gaus2 = stats.gaussian_kde(FX)
n2,x2 = np.histogram(FX, bins=binsx)
axHistx.plot(x2,gaus2(x2),color = 'darkorange',label = 'Future', linewidth = .5)

gaus3 = stats.gaussian_kde(PY)
n3,x3= np.histogram(PY, bins=binsy)
axHisty.plot(x3,gaus3(x3),orientation='horizontal',color = 'slateblue', label = 'Present', linewidth = .5)

gaus4 = stats.gaussian_kde(FY)
n4,x4= np.histogram(FY, bins=binsy)
axHisty.plot(x4,gaus4(x4),orientation='horizontal',color = 'darkorange',   label = 'Future', linewidth = .5)

axHistx.set_xlim( axScatter.get_xlim() )
axHistx.set_xticks(())
axHistx.set_yticks(())
axHisty.set_ylim( axScatter.get_ylim() )
axHisty.set_xticks(())
axHisty.set_yticks(())

运行时,我收到以下错误消息:

AttributeError: Unknown property orientation

我无法找到一种不同的方式来旋转像这样的带衬里的直方图。我非常感谢你的帮助!

0 个答案:

没有答案