Search code examples
matplotlibhistogramaxes

matplotlib axes histogram patches


How do you get the object from ax.hist() and then setp for the object. Here is what I mean:

n,bins2,patches =
ax2.hist(arra,bins=18,weights=1./bias,normed=False,color='#d9d9db')
ax2.hist.setp(edgecolor='g') 

Well, obviously this doesn't work! I am getting an error:

File "./bin_data.py", line 112, in <module>
    ax2.hist.setp(edgecolor='g')
AttributeError: 'function' object has no attribute 'setp'

Your help will be greatly appreciated!


Solution

  • Of course to change the edgecolor you may directly supply it to the histogram function

    n,bins2,patches = ax2.hist(..., facecolor='#d9d9db', edgecolor="g")
    

    To answer the question: The object to set the color to is the third return of hist, which is a container of bars

    n,bins2,patches = ax2.hist(..., color='#d9d9db')
    plt.setp(patches, edgecolor="g")