【发布时间】:2018-08-24 10:41:39
【问题描述】:
我正在尝试使用 matplotlib 和 python 3.7 进行绘图。
这是我的代码:
import matplotlib
fig = matplotlib.pyplot.figure()
rect = fig.patch
rect.set_facecolor("green")
x = [3, 7, 8, 12]
y = [5, 13, 2, 8]
graph1 = fig.add_subplot(1, 1, axisbg="black")
graph1.plot(x, y, "red", linewidth=4.0)
matplotlib.pyplot.show()
但我不断收到此错误:
File "C:\Users\User\Anaconda3\lib\site-packages\matplotlib\axes\_subplots.py", line 72, in __init__
raise ValueError('Illegal argument(s) to subplot: %s' % (args,))
ValueError: Illegal argument(s) to subplot: (1, 1)
有什么问题?
【问题讨论】:
-
能否修正一下错误信息的格式?
-
您可以将
fig.add_subplot(1,1,axisbg="black")替换为fig.add_subplot(111,axisbg="black")。
标签: python matplotlib python-3.7