【问题标题】:Matplotlib deprecation warning running through ubuntu application通过 ubuntu 应用程序运行的 Matplotlib 弃用警告
【发布时间】:2020-08-08 06:26:55
【问题描述】:

我在 Windows 上通过 shell 运行程序并不断收到此弃用错误。这是正在运行的代码和错误消息:

代码: 类窗口: """ 使用 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)

def show_img(self, img):

错误: /home/msaidi/gym-minigrid/gym_minigrid/window.py:31:MatplotlibDeprecationWarning:自 Matplotlib 3.2 起,不推荐按位置传递 set_xticks() 的次要参数;该参数将在以后的两个次要版本中成为仅关键字。 self.ax.set_xticks([], []) /home/msaidi/gym-minigrid/gym_minigrid/window.py:32:MatplotlibDeprecationWarning:自 Matplotlib 3.2 起,不推荐在位置上传递 set_yticks() 的次要参数;该参数将在以后的两个次要版本中成为仅关键字。 self.ax.set_yticks([], [])

当我在 ide 中编译代码时,我没有收到任何错误。

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

Matplotlib 版本:3.2.1 蟒蛇3 运行通过(ubuntu windows 应用)

【问题讨论】:

    标签: python shell ubuntu matplotlib


    【解决方案1】:

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

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

    【讨论】:

      【解决方案2】:

      只需将其更改为:

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

      该错误表示第二个参数不能按位置给出,这意味着您需要为第二个参数显式指定参数名称 minor=False 或在您的情况下删除第二个参数。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-03-08
        • 2017-09-29
        • 2012-09-07
        • 2018-06-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多