gpt4 book ai didi

python - Matplotlib 弃用 在 plt.show() 中设置值时发出警告。关键词是什么?

转载 作者:行者123 更新时间:2023-12-02 03:12:42 25 4
gpt4 key购买 nike

阅读 Joel Grus 的“从头开始数据科学”,并尝试在学习过程中编写示例代码。为了一次获得多个结果,我粘贴了我的代码(基于第 3 章中的示例 4)。

为了获得第二个数字,我发现我需要设置 plt.show(0)。但是,当我在括号中输入“0”或“False”时,我收到警告:

MatplotlibDeprecationWarning:自 Matplotlib 3.1 起,已弃用按位置传递 show() 的 block 参数;该参数在 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)

关于python - Matplotlib 弃用 在 plt.show() 中设置值时发出警告。关键词是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57167780/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com