[英]jupyter notebook prevent plot from showing up on class initialization
If I write following class: 如果我写以下课程:
from matplotlib import pyplot as plt
import numpy as np
class FigureShowingUp:
def __init__(self):
self.fig, self.ax = plt.subplots(ncols=1, figsize=(8,6))
def make_plot(self):
x = np.linspace(0, 1)
y = np.random.normal(loc=0, scale=1, size=len(x))
self.ax.scatter(x,y)
And import it in a notebook like: 并将其导入笔记本,例如:
from test_fig_class import FigureShowingUp
test = FigureShowingUp()
The plot always shows up upon initialization. 该图总是在初始化时显示。 How do I prevent that ?
我该如何预防呢?
I don't use notebooks very much, but presumably you have to turn off interactive plotting: 我不太用笔记本,但是想必您必须关闭交互式绘图:
from matplotlib import pyplot as plt; plt.ioff()
Then show the figure after making the plot: 然后在绘制绘图后显示该图:
def make_plot(self):
x = np.linspace(0, 1)
y = np.random.normal(loc=0, scale=1, size=len(x))
self.ax.scatter(x,y)
plt.show()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.