简体   繁体   English

%matplotlib内联不适用于模块内的绘图

[英]%matplotlib inline doesn't work for plots inside a module

having trouble displaying plots in ipython notebook 无法在ipython Notebook中显示情节

here is a simplified version of what I do: 这是我的工作的简化版本:

%matplotlib inline  
import MyPackage  
obj = MyPackage.MyObj()  
obj.display()  

inside MyPackage: 在MyPackage中:

import matplotlib.pyplot as plt  
class MyObj(object):  
    ......  
    def display(self):  
        plt.figure()
        plt.scatter(DATA_IN_MyObj)   

return I got: 我得到的回报:

<matplotlib.figure.Figure at 0x5de5b10>

thank you all very much! 非常感谢大家!

Since the plot command is inside your module, which has its own namespace, you have to append plt.show() in order to display the figure. 由于plot命令位于模块内部,模块具有自己的名称空间,因此必须附加plt.show()才能显示该图。

def display(self):  
    plt.scatter(DATA_IN_MyObj)
    plt.show()

plt.figure() is not necessary. plt.figure()

%matplotlib inline is IPython magic that imports many plotting functions and automatically issues plt.show() if one of these functions is detected in a cell. %matplotlib inline是IPython的魔术,可导入许多绘图功能,如果在单元格中检测到其中一个功能,则自动发出plt.show()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM