這工作:
In [1]: import matplotlib.pyplot as plt
In [2]: plt.plot([1,2,3],[4,5,6])
Out[2]: [<matplotlib.lines.Line2D at 0x30b2b10>]
In [3]: ax = plt.gca() # get axis handle
In [4]: line = ax.lines[0] # get the first line, there might be more
In [5]: line.get_xdata()
Out[5]: array([1, 2, 3])
In [6]: line.get_ydata()
Out[6]: array([4, 5, 6])
In [7]: line.get_xydata()
Out[7]:
array([[ 1., 4.],
[ 2., 5.],
[ 3., 6.]])
我發現這些在軸線物體周圍挖。我只能找到關於這些函數的一些minimal information,顯然你可以給它們一個布爾標誌來獲得原始數據或處理過的數據,不確定是什麼意思。
編輯:喬金頓呈略微更合適的方法來做到這一點:我發誓,我用Google搜索,我能想到的詞的每一個可能的組合
In [1]: import matplotlib.pyplot as plt
In [2]: lines = plt.plot([1,2,3],[4,5,6],[7,8],[9,10])
In [3]: lines[0].get_data()
Out[3]: (array([1, 2, 3]), array([4, 5, 6]))
In [4]: lines[1].get_data()
Out[4]: (array([7, 8]), array([ 9, 10]))
,但跨線程沒來!感謝您的鏈接。 – brettb
我只發現通過搜索'matplotlib get_xdata',而不是使用SO的標準搜索。 –
只是供參考:一般來說,matplotlib繪圖函數會返回一個'Artist'實例(或'plot'情況下的藝術家序列),其中包含數據,樣式信息等。許多藝術家具有'get_data'和'set_data'方法(例如,你可以做'x,y = line.get_data()')。對於某些人來說,該方法可能被稱爲別的東西(例如'scatter'返回一個集合,其中等價方法是'get_offsets')。一些藝術家(例如'ContourSets')不包含對原始輸入數據的引用,但是這是相當罕見的。基本上,你想要堅持繪圖功能的輸出。 –