Donbeo
Donbeo

Reputation: 17617

How to set xlim

I have this code:

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)

It works but the x axis goes from -8 to -2 while I would like from -10 to 0 Where is the error?

Upvotes: 1

Views: 21113

Answers (1)

leeladam
leeladam

Reputation: 1758

You set back your xrange to default with pl.axis('tight'). Try to remove that line, or put it before the xlim command.

The pyplot documentation says for pl.axis('tight'): "changes x and y axis limits such that all data is shown."

Upvotes: 2

Related Questions