Python 绘制特定x轴值的绘图,并在绘图中标记*(x,y)值
我想得到x轴值只跟在c值后面的图,这样c=[0.000001,0.00001,0.0001,0.001,0.01,1.0] 换句话说。我想显示每个c的y值 然后在绘图中用*或正方形标记(c,y)值 以下是我尝试过的:Python 绘制特定x轴值的绘图,并在绘图中标记*(x,y)值,python,matplotlib,plot,Python,Matplotlib,Plot,我想得到x轴值只跟在c值后面的图,这样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_
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()
我得到了以下信息:
我的代码有什么问题
编辑-1
我刚加了这行代码。它允许x轴比例以对数方式而不是线性方式变化您没有要求matplotlib使用标记。@Goyo,请查看我的更新。要查看这些值(0.000001,0.00001,0.0001,0.001,0.01,1.0)的标记,我需要具有x轴值:0.000001,0.00001,0.0001,0.001,0.011.0在该刻度中,而不是0,0.2,0.4,0.8。。这是我的问题,标记似乎位于指定的x位置。我不知道你想要什么。更改x刻度?对数刻度?一份预期结果的草稿会有所帮助。事实上,它们位于指定的位置。然而,为了清楚地显示它们,我需要改变x记号,以便在x轴上看到0.000001,0.00001,0.0001,0.001,0.01,1.0,而不是0.0,0.2,0.4,0.6,0.8,1.0,你可以随意改变。
ax2.set_xscale(value='log')