绘制特定x轴值的图表,并在图表中标记*(x,y)值

时间:2017-11-23 12:49:47

标签: python matplotlib plot

我希望仅使用c值得到x轴值的图,例如c = [0.000001,0.00001,0.0001,0.001,0.01,1.0]。

另一方面。我希望显示每个 c y 值。

然后在图中用*或正方形标记(c,y)值。

这是我试过的:

from sklearn.svm import LinearSVC
penalty_param=[]
lin_svm=[]
lin_svm_train=[]
for c in (0.000001,0.00001,0.0001,0.001,0.01,1.0):
   penalty_param.append(c)
   clf = LinearSVC(C=c)
   clf.fit(X_train,y_train)
   lin_svm.append(clf.score(X_test,y_test))
   lin_svm_train.append(clf.score(X_train,y_train))


fig2, ax2 = plt.subplots()
ax2.set_xslim((0.000001,0.00001,0.0001,0.001,0.01,1.0))
ax2.plot(penalty_param,lin_svm,label='Test accuracy',marker='o')
ax2.plot(penalty_param,lin_svm_train,label='Train accuracy ',marker='*')
ax2.set_xlabel(" C : penalty parameter")
ax2.set_ylabel("Accuracy")
ax2.legend(loc='best')
ax2.set_title(' Linear SVM classifier accuracy in terms of C parameter')
fig2.show()

我得到以下内容: enter image description here

我的代码出了什么问题?

修改-1 enter image description here

1 个答案:

答案 0 :(得分:0)

ax2.set_xscale(value='log')

我刚添加了这行代码。它允许使x轴刻度以对数方式而不是以线性方式变化