2017-04-17 118 views
-1

我想使用plt.show()顯示一些圖。我得到IPython控制檯上顯示的圖,但我需要在新窗口中看到每個圖。我能做什麼 ?plt.show()不會打開一個新的數字窗口

+0

請澄清。你想同時打開所有包含圖的窗口嗎?或者你只是想讓每個圖表在一個窗口中而不是在IPython控制檯中? –

+0

我想看到每個圖是一個單獨的窗口,而不是在IPython控制檯中。 – ufdul

+0

,因爲我需要在matplotlib._pylab_helpers.Gcf.get_all_fig_managers()中使用figure = [manager.canvas.figure for manager]來保存它們,我需要在一個單獨的數字窗口中打開每個圖的所有數字 – ufdul

回答

0

您想在您的iPython控制檯中輸入%matplotlib qt。這會改變它僅適用於您所處的會話。要改變它的未來,去Tools > Preferences,選擇iPython Console > Graphics,然後將Graphics Backend設置爲Qt4Qt5。這應該工作。

1

在你的筆記本,嘗試

import matplotlib.pyplot as plt 
    %matplotlib 

單獨調用這個樣子,也應該給輸出在單獨的窗口。根據您的系統,還有幾個選項可用於%matplotlib。要查看所有可用選項,使用

%matplotlib -l 

調用

%matplotlib inline 

將再次繪製在筆記本的地塊。

0

另一種選擇是使用plt.figure:

import matplotlib.pyplot as plt 
plt.figure(1)    # the first figure 
plt.subplot(211)    # the first subplot in the first figure 
plt.plot([1, 2, 3]) 
plt.subplot(212)    # the second subplot in the first figure 
plt.plot([4, 5, 6]) 
plt.show(block=False) 

plt.figure(2)    # a second figure 
plt.plot([4, 5, 6])   # creates a subplot(111) by default 
plt.show(block=False) 

plt.figure(1)    # figure 1 current; subplot(212) still current 
plt.subplot(211)    # make subplot(211) in figure1 current 
plt.title('Easy as 1, 2, 3') # subplot 211 title 
plt.show(block=False) 

(參見:https://matplotlib.org/users/pyplot_tutorial.html