首页 > 解决方案 > 如何阻止 plt.plot() 的输出在 Jupyter 笔记本中出现两次

问题描述

import numpy as np
import matplotlib.pyplot as plt

def myplot1(t,x):
    fig1 = plt.figure()
    _ = plt.plot(t,x)
    return fig1

def myplot2(t,x):
    fig2 = plt.figure()
    _ = plt.plot(t,x)
    return fig2

t = np.arange(0,6,0.01)
x = np.sin(t)
y = np.cos(t)

#calling the functions
myplot1(t,x)
myplot1(t,y)

正如上面提到的示例代码,我的目标是一个接一个地绘制两个图形。在函数定义中,我使用了 return 语句,因为如果需要我还想保存这些数字。我在这里面临的问题是每次我调用一个函数时,例如 myplot1(t,x) 都会出现两个数字。您能否就如何解决该问题提供一些见解?

标签: pythonmatplotlibjupyter-notebook

解决方案


推荐阅读