2016-02-10 28 views
3

創建一個特定的情節是很多工作,所以我想通過創建一個返回一個數字的函數f()來實現自動化。我可以告訴python將現有人物放入新圖中嗎?

我想調用這個函數,這樣我可以把結果放在一個子圖中。無論如何,我可以做到這一點?下面是一些僞代碼解釋了我的意思

figure_of_interest = f() 

fig,ax = plt.subplots(nrows = 4,cols = 1) 

ax[1].replace_with(figure_of_interest) 

回答

0

herehere之前有人問。

簡答:這是不可能的。

但是你可以隨時修改軸實例或使用函數來創建/修改當前軸:

import matplotlib.pyplot as plt 
import numpy as np 

def test(): 
    x = np.linspace(0, 2, 100) 

    # With subplots 
    fig1, (ax1, ax2) = plt.subplots(2) 
    plot(x, x, ax1) 
    plot(x, x*x, ax2) 

    # Another Figure without using axes 
    fig2 = plt.figure() 
    plot(x, np.exp(x)) 

    plt.show() 

def plot(x, y, ax=None): 
    if ax is None: 
     ax = plt.gca() 
    line, = ax.plot(x, y) 
    return line 

test() 
相關問題