如何使用python繪製多個圖在一個窗口

如何使用python繪製多個圖在一個窗口

代碼部分

import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
ax = fig.add_subplot(1,3,1)
x = np.linspace(-1,1,300)[:,np.newaxis]
y = np.linspace(-1,1,300)[:,np.newaxis]

[ax1, ax2, ax3] , [ax4, ax5, ax6] = fig.subplots(2, 3, sharey=True)
ax1.plot(x, y)
ax1.set_title(‘Sharing Y axis’)
ax2.scatter(x, y)
plt.show()

效果如圖

在這裏插入圖片描述