Ask Your Question
2

How do I create a log plot of line data?

asked 2011-07-26 18:54:24 +0100

tcfisher gravatar image

updated 2011-07-27 09:59:41 +0100

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 flag offensive close merge delete

Comments

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.

kcrisman gravatar imagekcrisman ( 2011-07-29 15:37:01 +0100 )edit

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

kcrisman gravatar imagekcrisman ( 2012-06-25 12:46:30 +0100 )edit

1 Answer

Sort by ยป oldest newest most voted
3

answered 2011-07-27 14:57:05 +0100

niles gravatar image

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])

linear plot

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

log plot

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)))

log plot with log ticks

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.

edit flag offensive delete link more

Comments

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)...

Erez gravatar imageErez ( 2012-07-01 12:07:46 +0100 )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)...

Erez gravatar imageErez ( 2012-07-01 12:07:47 +0100 )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!

Erez gravatar imageErez ( 2012-07-01 12:10:50 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2011-07-26 18:54:24 +0100

Seen: 1,762 times

Last updated: Jul 27 '11