【问题标题】:matplotlib show() doesnt show() in second callmatplotlib show() 在第二次调用中不显示()
【发布时间】:2021-09-10 02:59:40
【问题描述】:

我正在尝试在 Jupyter Notebook 中显示绘图。
当我第一次调用 plt.show() 时一切都很好,但是当我稍后在另一个单元格中调用它时,它不会显示情节。 我正在使用 %matplotlib 内联。

单元格 1

fig, ax = plt.subplots()
ax.set_title("Scatter Plot x1, x2")
ax.set_xlabel("x1")
ax.set_ylabel("x2")
ax.scatter(df["x1"], df["x2"], c=df["c"])
plt.show()

单元格 2,我在这里添加一个新点,并希望得到新的情节。

ax.scatter(center0[0], center0[1], c="red")
plt.show()

如果我删除单元格 2 中的 plt.show() 语句,我会得到

所以情节在那里,但它不会显示?

【问题讨论】:

    标签: python python-3.x matplotlib jupyter-notebook anaconda


    【解决方案1】:

    实际上你不需要再次绘制,你只需要调用你的图

    单元格 1:

    fig, ax = plt.subplots()
    ax.set_title("Scatter Plot x1, x2")
    ax.set_xlabel("x1")
    ax.set_ylabel("x2")
    ax.scatter(df["x1"], df["x2"], c=df["c"])
    plt.show()
    

    单元格 2:

    ax.scatter(center0[0], center0[1], c="red")
    fig
    

    我希望它能回答你的问题

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-12-31
      • 2019-06-05
      • 1970-01-01
      • 1970-01-01
      • 2011-03-20
      • 1970-01-01
      相关资源
      最近更新 更多