【问题标题】:How to prevent from drawing overlapping axis ticks when adding a line to scatter plot?向散点图添加线时如何防止绘制重叠的轴刻度?
【发布时间】:2017-10-09 01:58:12
【问题描述】:
fig, ax = plt.subplots()
ax = fig.add_subplot(111)
ax.scatter(X[1],y)
y_projection = X.dot(theta_after)
ax.plot(X[1], y_projection)
plt.show()

以上是我的代码。我要做的基本上是为数据拟合一条线。我使用梯度下降法来找到合适的 theta。

我遇到的问题是上面的代码创建了两个 x 轴和 y 轴,并且它们相互重叠

This is the result generated from the above code. I'm not allowed to embed a pic now, please click on this to open the pic.

X - 是一个 97*2 矩阵,其中第一列全为 1。

【问题讨论】:

    标签: python-3.x matplotlib scatter-plot


    【解决方案1】:

    你正在用你的第二行创建一个额外的轴。只需删除以下行:

    ax = fig.add_subplot(111)
    

    当你运行fig, ax = plt.subplots()时,你已经有一个轴了

    【讨论】:

      猜你喜欢
      • 2020-10-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-11-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多