我正在按照本教程水平制作两个子图。根据示例,以下内容应该有效。
import matplotlib.pylab as plt
import numpy
# Sample data
x = numpy.linspace(0, 2 * numpy.pi, 400)
y1 = numpy.sin(x ** 2)
y2 = numpy.cos(x ** 2)
figure, axes = plt.subplots(1, 2)
axes[0, 0].plot(x, y)
axes[0, 1].plot(x, y)
Run Code Online (Sandbox Code Playgroud)
不幸的是,我收到以下错误消息。
---------------------------------------------------------------------------
IndexError Traceback (most recent call last)
<ipython-input-4-124cb6e8d977> in <module>
8
9 figure, axes = plt.subplots(1, 2)
---> 10 axes[0, 0].plot(x, y)
11 axes[0, 1].plot(x, y)
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed …Run Code Online (Sandbox Code Playgroud)