在 plt.show() 中设置值时出现 Matplotlib 弃用警告。关键词是什么?
Matplotlib Deprecation Warning when setting a value in plt.show(). What are the keywords?
阅读 Joel Grus 的 "Data Science from Scratch" 并尝试编写示例代码。为了一次弄清楚一个以上的数字,我粘贴了我编码的内容(基于第 3 章中的示例 4)。
为了获得我发现的第二个数字,我需要设置 plt.show(0)。但是,当我在括号中输入“0”或 'False' 时,我收到警告:
MatplotlibDeprecationWarning:从 Matplotlib 3.1 开始,不推荐按位置传递 show() 的块参数;该参数将在 3.3 中变为仅关键字。
from matplotlib import pyplot as plt
mentions = [500, 505]
years = [2013, 2014]
plt.figure(1)
plt.bar(years, mentions, 0.8)
plt.xticks(years)
plt.ylabel("# of times I heard someone say 'data science'")
# if you don't do this, matplotlib will label the x-axis 0, 1
# and then add a +2.013e3 off in the corner (bad matplotlib!)
plt.ticklabel_format(useOffset=False)
# misleading y-axis only shows the part above 500
plt.axis([2012,2015,499,506])
plt.title("Look at the 'Huge' Increase!")
plt.show(0)
plt.figure(2)
plt.bar(years, mentions, 0.8)
plt.xticks(years)
plt.ylabel("# of times I heard someone say 'data science'")
# if you don't do this, matplotlib will label the x-axis 0, 1
# and then add a +2.013e3 off in the corner (bad matplotlib!)
plt.ticklabel_format(useOffset=False)
plt.axis([2012,2015,0,550])
plt.title("Not So Huge Anymore")
plt.show()
plt.show(False)
结果
MatplotlibDeprecationWarning: Passing the block parameter of show() positionally is deprecated since Matplotlib 3.1; the parameter will become keyword-only in 3.3.
这是乱七八糟的。您将需要使用关键字参数:
plt.show(block=False)
阅读 Joel Grus 的 "Data Science from Scratch" 并尝试编写示例代码。为了一次弄清楚一个以上的数字,我粘贴了我编码的内容(基于第 3 章中的示例 4)。
为了获得我发现的第二个数字,我需要设置 plt.show(0)。但是,当我在括号中输入“0”或 'False' 时,我收到警告:
MatplotlibDeprecationWarning:从 Matplotlib 3.1 开始,不推荐按位置传递 show() 的块参数;该参数将在 3.3 中变为仅关键字。
from matplotlib import pyplot as plt
mentions = [500, 505]
years = [2013, 2014]
plt.figure(1)
plt.bar(years, mentions, 0.8)
plt.xticks(years)
plt.ylabel("# of times I heard someone say 'data science'")
# if you don't do this, matplotlib will label the x-axis 0, 1
# and then add a +2.013e3 off in the corner (bad matplotlib!)
plt.ticklabel_format(useOffset=False)
# misleading y-axis only shows the part above 500
plt.axis([2012,2015,499,506])
plt.title("Look at the 'Huge' Increase!")
plt.show(0)
plt.figure(2)
plt.bar(years, mentions, 0.8)
plt.xticks(years)
plt.ylabel("# of times I heard someone say 'data science'")
# if you don't do this, matplotlib will label the x-axis 0, 1
# and then add a +2.013e3 off in the corner (bad matplotlib!)
plt.ticklabel_format(useOffset=False)
plt.axis([2012,2015,0,550])
plt.title("Not So Huge Anymore")
plt.show()
plt.show(False)
结果
MatplotlibDeprecationWarning: Passing the block parameter of show() positionally is deprecated since Matplotlib 3.1; the parameter will become keyword-only in 3.3.
这是乱七八糟的。您将需要使用关键字参数:
plt.show(block=False)