Search code examples
pythonmatplotlibplotfiguredeprecation-warning

Matplotlib Deprecation Warning when setting a value in plt.show(). What are the keywords?


Going through "Data Science from Scratch" by Joel Grus and trying to code the examples as I go along. Trying to get more than one figure out at a time, I'm pasting what I coded (based on Example 4 in chapter 3).

In order to get the second figure I found I need to set plt.show(0). However when I put in the '0' or 'False' in the bracket I get a warning:

MatplotlibDeprecationWarning: Passing the block parameter of show() positionally is deprecated since Matplotlib 3.1; the parameter will become keyword-only in 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()

Solution

  • plt.show(False)
    

    results in

    MatplotlibDeprecationWarning: Passing the block parameter of show() positionally is deprecated since Matplotlib 3.1; the parameter will become keyword-only in 3.3.

    This is to be taken litterally. You will need to use a keyword argument:

    plt.show(block=False)