# How do I create a log plot of line data?

Is there a good way to create a log-log plot of line data in sage? I can't find it through the plot or line interfaces.

edit retag close merge delete

Sadly not yet - this is an often-requested thing - see http://trac.sagemath.org/sage_trac/ticket/4529. Niles' answers are as good as any.

( 2011-07-29 15:37:01 +0200 )edit

Update - this ticket has positive review, and hopefully will be in Sage 5.2.

( 2012-06-25 12:46:30 +0200 )edit

Sort by ยป oldest newest most voted

You could rescale the data before you plot it:

sage: data = [(t^2,t^3) for t in srange(1,10,.1)]
sage: L = line2d(data)
sage: L.show(figsize=[5,2])


sage: log_data = [(log(x[0]),log(x[1])) for x in data]
sage: M = line2d(log_data)
sage: M.show(figsize=[5,2])


If you want the tick marks to be logarithmic, the docstring for M.show describes an option for using a matplotlib tick "locator".

sage: from matplotlib import ticker
sage: tloc = lambda m: ticker.LogLocator(subs=[m])
sage: M.show(figsize=[5,2],ticks=(tloc(4),tloc(1)))


To be honest though, I had a lot of trouble using the LogLocator -- it doesn't seem completely polished, and may take a while to understand.

more

Hey, this seems to give nice results in terms of the shape of the graphs, but I don't get lables on the 'X' axis this way so I can't tell... Even in your example, change the - 4 in the 'tloc(4)' to 10 , and u don't get any lables, ('2' will give you only one lable , for - 0.2)...

( 2012-07-01 12:07:46 +0200 )edit

Hey, this seems to give nice results in terms of the shape of the graphs, but I don't get lables on the 'X' axis this way so I can't tell... Even in your example, change the - 4 in the 'tloc(4)' to 10 , and u don't get any lables, ('2' will give you only one lable , for - 0.2)...

( 2012-07-01 12:07:47 +0200 )edit

Moreover, I wish I could get the labels in shape of - 4X10^(-1), 4X10^0,...4X10^5... - Not as - 0.4,4,...,400000. Any hope?? - Appreciate your help a lot!

( 2012-07-01 12:10:50 +0200 )edit