如何在python matplotlib pyplot中设置xlim?

2024-04-27 04:25:58 发布

您现在位置:Python中文网/ 问答频道 /正文

我有这个密码:

import matplotlib.pyplot as pl
pl.plot(np.log(alphas_lasso),coefs_lasso.T) #this generate a plot which xlim=[-8,-2]
for alpha in alpha_min:
    pl.axvline(np.log(alpha),0,1) #add vertical line for every value of alpha
pl.xlim([-10,0]) # the xlim value I would like to set
pl.xlabel('Log(alpha)')
pl.ylabel('coefficients')
pl.title('Lasso Path')
pl.axis('tight')
pl.show()
print "log(alpha_min)=",log(alpha_min)

它可以工作,但是x轴从-8到-2,而我想从-10到0,错误在哪里?


Tags: importalphalog密码forplotmatplotlibvalue