Dav*_*eus 2 python plot matplotlib figure deprecation-warning
阅读 Joel Grus 的“从头开始数据科学”,并尝试在阅读过程中编写示例代码。为了一次获得多个结果,我粘贴了我的代码(基于第 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()
Run Code Online (Sandbox Code Playgroud)
plt.show(False)
Run Code Online (Sandbox Code Playgroud)
结果是
MatplotlibDeprecationWarning:自 Matplotlib 3.1 起,不推荐按位置传递 show() 的块参数;在 3.3 中该参数将变为仅限关键字。
这应该从字面上理解。您将需要使用关键字参数:
plt.show(block=False)
Run Code Online (Sandbox Code Playgroud)