Python matplotlib散点历史,直方图中带有阶梯填充的历史类型

Python matplotlib散点历史,直方图中带有阶梯填充的历史类型,python,matplotlib,histogram,Python,Matplotlib,Histogram,我修改了scatter_hist.py示例,发现有两个数据集需要绘制 我希望有“stepfilled”类型的直方图,但是如果我设置了“stepfilled”类型,Y轴直方图(orientation=“horizontal”)就不起作用了 有没有其他方法让柱状图看起来像“阶梯填充”式的,或者我做错了什么 下面是我使用histtype=“bar”的代码,展示了我的想法。换成 histtype="stepfilled" 要获得奇怪的直方图: import numpy as np import mat

我修改了scatter_hist.py示例,发现有两个数据集需要绘制

我希望有“stepfilled”类型的直方图,但是如果我设置了“stepfilled”类型,Y轴直方图(orientation=“horizontal”)就不起作用了

有没有其他方法让柱状图看起来像“阶梯填充”式的,或者我做错了什么

下面是我使用histtype=“bar”的代码,展示了我的想法。换成

histtype="stepfilled"
要获得奇怪的直方图:

import numpy as np
import matplotlib.pyplot as plt

# the random data
x = np.random.randn(1000)
y = np.random.randn(1000)

x_vals = [x]
y_vals = [y]
x_vals.append( np.random.randn( 300 ) )
y_vals.append( np.random.randn( 300 ) )

fig = plt.figure(1, figsize=(5.5,5.5))

from mpl_toolkits.axes_grid1 import make_axes_locatable

colour_LUT = ['#0000FF',
              '#00FF00']

# the scatter plot:
xymax = np.max(np.fabs(x))
colors = []
axScatter = plt.subplot(111)
for i in range( len(x_vals ) ):
    colour = colour_LUT[i]
    xymax = np.max( [np.max(np.fabs(x)), np.max(np.fabs(y)), xymax ] )
    axScatter.scatter( x_vals[i], y_vals[i], color = colour )
    colors.append(colour)

axScatter.set_aspect(1.)

# create new axes on the right and on the top of the current axes
# The first argument of the new_vertical(new_horizontal) method is
# the height (width) of the axes to be created in inches.
divider = make_axes_locatable(axScatter)
axHistx = divider.append_axes("top", 1.2, pad=0.1, sharex=axScatter)
axHisty = divider.append_axes("right", 1.2, pad=0.1, sharey=axScatter)

# make some labels invisible
plt.setp(axHistx.get_xticklabels() + axHisty.get_yticklabels(),
         visible=False)

# now determine nice limits by hand:
binwidth = 0.25

lim = ( int(xymax/binwidth) + 1) * binwidth

bins = np.arange(-lim, lim + binwidth, binwidth)
histtype = "bar"
axHistx.hist(x_vals, bins=bins, histtype= histtype, color=colors)
axHisty.hist(y_vals, bins=bins, orientation='horizontal',histtype= histtype, color=colors)

# the xaxis of axHistx and yaxis of axHisty are shared with axScatter,
# thus there is no need to manually adjust the xlim and ylim of these
# axis.

#axHistx.axis["bottom"].major_ticklabels.set_visible(False)
for tl in axHistx.get_xticklabels():
    tl.set_visible(False)
axHistx.set_yticks([0, 50, 100])

#axHisty.axis["left"].major_ticklabels.set_visible(False)
for tl in axHisty.get_yticklabels():
    tl.set_visible(False)
axHisty.set_xticks([0, 50, 100])

plt.draw()
plt.show()
谢谢你的帮助

编辑:

以下是我在windows环境下使用matplotlib 1.0.0接收到的图像。 使用histtype=“bar”我有:

使用histtype=“stepfilled”我有:

在使用“bar”和“barstacked”时,只提到了多个数据的特殊情况,我认为这意味着其他两种类型没有正确实现。将代码更改为添加多个直方图,而不是仅添加一个直方图对我来说很有效:

histtype = "stepfilled"
for i in xrange(len(x_vals)):
    axHistx.hist(x_vals[i], bins=bins, histtype= histtype, color=colors[i])
    axHisty.hist(y_vals[i], bins=bins, orientation='horizontal',histtype= histtype, color=colors[i])

谢谢你的回答,海宁。matplotlib的版本是什么?您在windows上运行它吗?我在windows 7上运行python 2.6.6中的matplotlib版本1.0.0