2015-06-09 74 views
3

我是Python新手,我只是在iPython Notebook中繪製了一個非常簡單的圖形。在iPython Notebook中使用matplotlib.pyplot

import matplotlib.pyplot as plt 
    plt.plot([1,2,3,4]) 
    plt.show() 

這是我寫的,期待一個簡單的對角線圖,但是當我運行它時,根本沒有任何打印。

如果我刪除

plt.show() 

我得到這個作爲輸出:

[<matplotlib.lines.Line2D at 0x109fcdb50>] 

如何獲得劇情說明了什麼?

+2

好吧,我發現我需要 %matplotlib直列 添加到頂部。 – user4794127

回答

-1

我也是新MatPlotLib但這樣本讓我一個簡單的正弦波曲線

的關鍵是調用

plt.draw()

完整的代碼如下。

from math import sin 
from matplotlib import pyplot as plt 


def plot_update(x_data, y_data, lcl_my_title, lcl_x_lbl, lcl_y_lbl, legend): 
    plt.grid(color='b', linestyle='--', linewidth=1) 
    plt.ylabel(lcl_y_lbl) 
    plt.xlabel(lcl_x_lbl) 
    plt.title(lcl_my_title) 
    plt.plot(x_data, y_data, label=legend) 
    plt.legend(loc=3, prop={'size': 6}) 
    plt.draw() 
    plt.show() 
    return 


t = range(0, 360, 1) 
s = [] 

for x in t: 
    s.append(sin(x)) 

print len(t) 
print len(s) 

plot_update(t, s, 'new graph', 'voltage', 'current', 'blah') 
+1

這不回答這個問題; OP詢問在ipython筆記本上繪圖,這不能解決問題 – tom

+0

@tom是的,你確實是對的。我沒有很好地閱讀OP的文章。抱歉。 – JamesD

相關問題