【发布时间】:2020-09-02 12:49:23
【问题描述】:
我想在 matplotlib 的图中增加两个数字之间的除法次数。
例如,在我的情节中,0 和 1 之间只有一个可见的除法,即 0.5。我想将可见的分区数增加到 9,即 0 到 1 之间的 0.1 到 0.9。
有什么办法吗?
代码:-
import matplotlib.pyplot as plt
X = np.array(features_train)
y = np.array(labels_train)
def make_meshgrid(x, y, h=.02):
x_min, x_max = x.min() - 0.1, x.max() + 0.1
y_min, y_max = y.min() - 0.1, y.max() + 0.1
xx, yy = np.meshgrid(np.arange(x_min, x_max, h),
np.arange(y_min, y_max, h))
return xx, yy
def plot_contours(ax, clf, xx, yy, **params):
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
out = ax.contourf(xx, yy, Z, **params)
return out
fig, ax = plt.subplots()
title = ('Decision surface of linear SVC ')
X0, X1 = X[:, 0], X[:, 1]
xx, yy = make_meshgrid(X0, X1)
plot_contours(ax, clf, xx, yy, cmap=plt.cm.coolwarm, alpha=1)
ax.scatter(X0, X1, c=y, cmap=plt.cm.coolwarm, s=20, edgecolors='k')
ax.set_ylabel('X 2')
ax.set_xlabel('X 1')
ax.set_title(title)
【问题讨论】:
-
随意编辑问题,以便更好地传达含义。
-
是什么样的情节?线、条、直方图?
-
折线图,SVM中用于显示决策边界的图。
-
好的,你能发布你用来生成情节的代码吗?因为我正在用 0 和 1 绘制一条线,其中有 0.1 个分区。
-
我已经编辑了问题并在那里发布了代码。
标签: python python-3.x matplotlib plot graph