Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 从matplotlib AXESSUBBLOT获取值_Python_Pandas_Matplotlib - Fatal编程技术网

Python 从matplotlib AXESSUBBLOT获取值

Python 从matplotlib AXESSUBBLOT获取值,python,pandas,matplotlib,Python,Pandas,Matplotlib,我想从方法返回的matplotlib.axes.AxesSubplot中获取值。 有没有办法做到这一点?我在列表中找不到该属性 import pandas as pd import matplotlib.pyplot as plt serie = pd.Series([0.0,950.0,-70.0,812.0,0.0,-90.0,0.0,0.0,-90.0,0.0,-64.0,208.0,0.0,-90.0,0.0,-80.0,0.0,0.0,-80.0,-48.0,840.0,-100.0

我想从方法返回的
matplotlib.axes.AxesSubplot
中获取值。 有没有办法做到这一点?我在列表中找不到该属性

import pandas as pd
import matplotlib.pyplot as plt

serie = pd.Series([0.0,950.0,-70.0,812.0,0.0,-90.0,0.0,0.0,-90.0,0.0,-64.0,208.0,0.0,-90.0,0.0,-80.0,0.0,0.0,-80.0,-48.0,840.0,-100.0,190.0,130.0,-100.0,-100.0,0.0,-50.0,0.0,-100.0,-100.0,0.0,-90.0,0.0,-90.0,-90.0,63.0,-90.0,0.0,0.0,-90.0,-80.0,0.0,])
hist = serie.hist()
# I want to get values of hist variable.

我知道我可以使用
np.histogram
获得直方图值,但我想使用pandas hist方法。

正如
xnx
在评论中指出的那样,这不像使用
plt.hist
那么容易访问。但是,如果您确实想使用pandas
hist
函数,则可以从调用
serie.hist
时添加到
hist
axesssubplot
补丁中获取此信息

下面是一个函数,用于在面片中循环,并返回面元边缘和直方图计数:

import pandas as pd
import matplotlib.pyplot as plt

serie = pd.Series([0.0,950.0,-70.0,812.0,0.0,-90.0,0.0,0.0,-90.0,0.0,-64.0,208.0,0.0,-90.0,0.0,-80.0,0.0,0.0,-80.0,-48.0,840.0,-100.0,190.0,130.0,-100.0,-100.0,0.0,-50.0,0.0,-100.0,-100.0,0.0,-90.0,0.0,-90.0,-90.0,63.0,-90.0,0.0,0.0,-90.0,-80.0,0.0,])
hist = serie.hist()

def get_hist(ax):
    n,bins = [],[]
    for rect in ax.patches:
        ((x0, y0), (x1, y1)) = rect.get_bbox().get_points()
        n.append(y1-y0)
        bins.append(x0) # left edge of each bin
    bins.append(x1) # also get right edge of last bin

    return n,bins

n, bins = get_hist(hist)

print n
print bins

plt.show()
下面是
n
bin
的输出:

[36.0, 1.0, 3.0, 0.0, 0.0, 0.0, 0.0, 0.0, 2.0, 1.0]                          # n
[-100.0, 5.0, 110.0, 215.0, 320.0, 425.0, 530.0, 635.0, 740.0, 845.0, 950.0] # bins
下面是要检查的直方图:


我不确定这是否可行:熊猫似乎会扔掉matplotlib返回给它的装箱数据、装箱边和面片对象。为什么不直接用
plt.hist
绘图?