将线添加到散点图时如何防止绘制重叠的轴刻度?
How to prevent from drawing overlapping axis ticks when adding a line to scatter plot?
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。
您正在用第二行创建一个额外的轴。只需删除以下行:
ax = fig.add_subplot(111)
当您 运行 fig, ax = plt.subplots()
时,您已经拥有了一把斧头
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。
您正在用第二行创建一个额外的轴。只需删除以下行:
ax = fig.add_subplot(111)
当您 运行 fig, ax = plt.subplots()