Python VS代码图

Python VS代码图,python,matplotlib,visual-studio-code,Python,Matplotlib,Visual Studio Code,我对VS代码有奇怪的问题。 通常我有一个函数,它允许你在一个图形上画两个函数。(下面的代码) 在Pycharm中,我没有任何问题,它显示了我的情节。 在VS代码中,我有main函数和Jupyter笔记本,在这里我导入main并调用该函数。 没有错误,但它没有显示我的情节 代码: 提前感谢您的帮助;) 你能试试这个吗 import numpy as np import pickle import matplotlib import matplotlib.pyplot as plt import s

我对VS代码有奇怪的问题。 通常我有一个函数,它允许你在一个图形上画两个函数。(下面的代码) 在Pycharm中,我没有任何问题,它显示了我的情节。 在VS代码中,我有main函数和Jupyter笔记本,在这里我导入main并调用该函数。 没有错误,但它没有显示我的情节

代码:

提前感谢您的帮助;)

你能试试这个吗

import numpy as np
import pickle
import matplotlib
import matplotlib.pyplot as plt
import string
import random

def compare_plot(x1:np.ndarray,y1:np.ndarray,x2:np.ndarray,y2:np.ndarray,
                 xlabel: str,ylabel:str,title:str,label1:str,label2:str):

    if x1.shape != y1.shape or  min(x1.shape)==0 or x2.shape != y2.shape or  min(x2.shape)==0:
        return None

    else:
        fig, ax = plt.subplots(figsize=(8, 8))
        ax.plot(x1, y1, 'b', linewidth = 4)
        ax.plot(x2, y2, 'r', linewidth = 2)
        ax.set_xlabel(xlabel)
        ax.set_ylabel(ylabel)
        ax.set_title(title)
        ax.legend([label1, label2])
        plt.tight_layout()
        plt.show()

x = np.linspace(0, 5, 100)
f = x + 2
g = x**2 - 2 * np.sin(x) + 3
compare_plot(f, g, x, x, 'x', 'y', 'graphic solution', 'f(x)', 'g(x)')
import numpy as np
import pickle
import matplotlib
import matplotlib.pyplot as plt
import string
import random

def compare_plot(x1:np.ndarray,y1:np.ndarray,x2:np.ndarray,y2:np.ndarray,
                 xlabel: str,ylabel:str,title:str,label1:str,label2:str):

    if x1.shape != y1.shape or  min(x1.shape)==0 or x2.shape != y2.shape or  min(x2.shape)==0:
        return None

    else:
        fig, ax = plt.subplots(figsize=(8, 8))
        ax.plot(x1, y1, 'b', linewidth = 4)
        ax.plot(x2, y2, 'r', linewidth = 2)
        ax.set_xlabel(xlabel)
        ax.set_ylabel(ylabel)
        ax.set_title(title)
        ax.legend([label1, label2])
        plt.tight_layout()
        plt.show()

x = np.linspace(0, 5, 100)
f = x + 2
g = x**2 - 2 * np.sin(x) + 3
compare_plot(f, g, x, x, 'x', 'y', 'graphic solution', 'f(x)', 'g(x)')