在Ubuntu应用程序中运行的Matplotlib弃用警告



我正在Windows上通过shell运行一个程序,并不断收到此弃用警告。以下是正在运行的代码和错误消息:

代码:

class Window:
"""Window to draw a gridworld instance using Matplotlib"""
def __init__(self, title):
self.fig = None
self.imshow_obj = None
# Create the figure and axes
self.fig, self.ax = plt.subplots()
# Show the env name in the window title
self.fig.canvas.set_window_title(title)
# Turn off x/y axis numbering/ticks
self.ax.set_xticks([], [])
self.ax.set_yticks([], [])
# Flag indicating the window was closed
self.closed = False
def close_handler(evt):
self.closed = True
self.fig.canvas.mpl_connect('close_event', close_handler)

输出:

/home/msaidi/gym-minigrid/gym_minigrid/window.py:31: MatplotlibDeprecationWarning: Passing the minor parameter of set_xticks() positionally is deprecated since Matplotlib 3.2; the parameter will become keyword-only two minor releases later.
self.ax.set_xticks([], [])
/home/msaidi/gym-minigrid/gym_minigrid/window.py:32: MatplotlibDeprecationWarning: Passing the minor parameter of set_yticks() positionally is deprecated since Matplotlib 3.2; the parameter will become keyword-only two minor releases later.
self.ax.set_yticks([], [])

当我在IDE中运行代码时,我不会得到任何错误。

我尝试从self.ax.set_xticks更改为set_xticksax.set_xticksself.set_xticks,但没有成功。

工具信息:

  • Matplotlib版本:3.2.1
  • Python 3
  • 通过Ubuntu Windows应用程序运行

您需要将刻度值和刻度标签分开。

ax.set_xticks([]) # values
ax.set_xticklabels([]) # labels

只需将其更改为:

self.ax.set_xticks([])
self.ax.set_yticks([])

错误表明第二个参数不能按位置给定,这意味着您需要为第二个变量显式给定参数name minor=False,或者在您的情况下删除第二个常量。

最新更新