【问题标题】:MatplotlibDeprecationWarning when adding background color to subplots向子图添加背景颜色时的 MatplotlibDeprecationWarning
【发布时间】:2020-08-12 11:10:00
【问题描述】:

我正在尝试从数据集中创建一个箱线图,然后更改每个子图的背景颜色:

url = "https://raw.githubusercontent.com/jbrownlee/Datasets/master/iris.csv"
column_names = ['sepal-length', 'sepal-width', 'petal-length', 'petal-width', 'class']
data_set = read_csv(url, names=column_names)


data_set.plot(kind="box", subplots=True, color="yellow", layout=(2, 2), sharex=False, sharey=False)

pyplot.subplot(221).set_facecolor("red")
pyplot.subplot(222).set_facecolor("purple")
pyplot.subplot(223).set_facecolor("green")
pyplot.subplot(224).set_facecolor("blue")

pyplot.show()

我确实得到了彩色子图,但是,我不断收到警告消息:

MatplotlibDeprecationWarning: Adding an axes using the same arguments as a previous axes currently reuses the earlier instance.  In a future version, a new instance will always be created and returned.  Meanwhile, this warning can be suppressed, and the future behavior ensured, by passing a unique label to each axes instance.

有人知道如何解决这个问题吗?

【问题讨论】:

    标签: python matplotlib


    【解决方案1】:

    这似乎是 Matplotlib 中一个持续存在的问题,截至今天尚未解决。通过阅读此处here 的线程,似乎没有迫在眉睫的弃用风险。

    但是,如果您希望此消息消失,您可以尝试该用户尝试过的here.。此处用户将fig.subplot()替换为fig.add_subplot()

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2023-02-21
      • 1970-01-01
      • 2019-01-05
      • 2016-11-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-11-12
      相关资源
      最近更新 更多