在每个子图中绘制自定义函数

Plot custom functions in each subplot

我有一些自定义函数可以绘制某些分析的结果。我想在图形的子图中显示每个图,例如

---------------------------
|   Plot 1   |   Plot 2   |
|            |            |
---------------------------
|   Plot 3   |   Plot 4   |
|            |            |
---------------------------

这是一个 MWE:

import numpy as np
import matplotlib.pyplot as plt

def plot_sin():
    x = np.linspace(0, 10)
    y = np.sin(x)
    plt.plot(x, y)
    plt.title('Just a sine curve')

def plot_int():
    x = np.linspace(-10, 10)
    y = np.sin(x) / x
    plt.plot(x, y)
    plt.title('Looks like an interference pattern')

def plot_hist():
    x = np.random.normal(0.2, 0.05, 1000)
    plt.hist(x)
    plt.title('Oh look, it\'s a histogram')

def plot_sin_cos():
    x = np.linspace(-3*np.pi, 3*np.pi, 1000)
    y = np.sin(x) / np.cos(x)
    plt.plot(x, y)
    plt.title('Yet another siney plot')

plot_sin()
plot_int()
plot_hist()
plot_sin_cos()

fig, ax = plt.subplots(2, 2)
ax[0, 0].plot_sin()
ax[1, 0].plot_int()
ax[0, 1].plot_hist()
ax[1, 1].plot_sin_cos()

但当然 'AxesSubplot' object has no attribute 'plot_sin'。如何将我的每个函数绘制在单独的子图中?

我会这样做:

# pass the axis here and the other functions as well
def plot_sin(ax):
    x = np.linspace(0, 10)
    y = np.sin(x)
    ax.plot(x, y)
    ax.set_title('Just a sine curve')

fig, ax = plt.subplots(2,2)
plot_sin(ax[0,0])