小编Sud*_*nha的帖子

matplotlib 子图的奇怪之处

我正在按照教程水平制作两个子图。根据示例,以下内容应该有效。

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)

python matplotlib subplot

4
推荐指数
1
解决办法
874
查看次数

标签 统计

matplotlib ×1

python ×1

subplot ×1