ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sun, 01 Jul 2012 05:10:50 -0500How do I create a log plot of line data?http://ask.sagemath.org/question/8243/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. Tue, 26 Jul 2011 11:54:24 -0500http://ask.sagemath.org/question/8243/how-do-i-create-a-log-plot-of-line-data/Comment by kcrisman for <p>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. </p>
http://ask.sagemath.org/question/8243/how-do-i-create-a-log-plot-of-line-data/?comment=19510#post-id-19510Update - this ticket has positive review, and hopefully will be in Sage 5.2.Mon, 25 Jun 2012 05:46:30 -0500http://ask.sagemath.org/question/8243/how-do-i-create-a-log-plot-of-line-data/?comment=19510#post-id-19510Comment by kcrisman for <p>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. </p>
http://ask.sagemath.org/question/8243/how-do-i-create-a-log-plot-of-line-data/?comment=21443#post-id-21443Sadly not yet - this is an often-requested thing - see http://trac.sagemath.org/sage_trac/ticket/4529. Niles' answers are as good as any.Fri, 29 Jul 2011 08:37:01 -0500http://ask.sagemath.org/question/8243/how-do-i-create-a-log-plot-of-line-data/?comment=21443#post-id-21443Answer by niles for <p>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. </p>
http://ask.sagemath.org/question/8243/how-do-i-create-a-log-plot-of-line-data/?answer=12538#post-id-12538You 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](/upfiles/13117890862047407.png)
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](/upfiles/13117891387182985.png)
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](/upfiles/1311789302896444.png)
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.
Wed, 27 Jul 2011 07:57:05 -0500http://ask.sagemath.org/question/8243/how-do-i-create-a-log-plot-of-line-data/?answer=12538#post-id-12538Comment by Erez for <p>You could rescale the data before you plot it:</p>
<pre><code>sage: data = [(t^2,t^3) for t in srange(1,10,.1)]
sage: L = line2d(data)
sage: L.show(figsize=[5,2])
</code></pre>
<p><img alt="linear plot" src="/upfiles/13117890862047407.png"/></p>
<pre><code>sage: log_data = [(log(x[0]),log(x[1])) for x in data]
sage: M = line2d(log_data)
sage: M.show(figsize=[5,2])
</code></pre>
<p><img alt="log plot" src="/upfiles/13117891387182985.png"/></p>
<p>If you want the tick marks to be logarithmic, the docstring for <code>M.show</code> describes an option for using a matplotlib tick "locator".</p>
<pre><code>sage: from matplotlib import ticker
sage: tloc = lambda m: ticker.LogLocator(subs=[m])
sage: M.show(figsize=[5,2],ticks=(tloc(4),tloc(1)))
</code></pre>
<p><img alt="log plot with log ticks" src="/upfiles/1311789302896444.png"/></p>
<p>To be honest though, I had a lot of trouble using the <code>LogLocator</code> -- it doesn't seem completely polished, and may take a while to understand.</p>
http://ask.sagemath.org/question/8243/how-do-i-create-a-log-plot-of-line-data/?comment=19463#post-id-19463Hey, 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)... Sun, 01 Jul 2012 05:07:47 -0500http://ask.sagemath.org/question/8243/how-do-i-create-a-log-plot-of-line-data/?comment=19463#post-id-19463Comment by Erez for <p>You could rescale the data before you plot it:</p>
<pre><code>sage: data = [(t^2,t^3) for t in srange(1,10,.1)]
sage: L = line2d(data)
sage: L.show(figsize=[5,2])
</code></pre>
<p><img alt="linear plot" src="/upfiles/13117890862047407.png"/></p>
<pre><code>sage: log_data = [(log(x[0]),log(x[1])) for x in data]
sage: M = line2d(log_data)
sage: M.show(figsize=[5,2])
</code></pre>
<p><img alt="log plot" src="/upfiles/13117891387182985.png"/></p>
<p>If you want the tick marks to be logarithmic, the docstring for <code>M.show</code> describes an option for using a matplotlib tick "locator".</p>
<pre><code>sage: from matplotlib import ticker
sage: tloc = lambda m: ticker.LogLocator(subs=[m])
sage: M.show(figsize=[5,2],ticks=(tloc(4),tloc(1)))
</code></pre>
<p><img alt="log plot with log ticks" src="/upfiles/1311789302896444.png"/></p>
<p>To be honest though, I had a lot of trouble using the <code>LogLocator</code> -- it doesn't seem completely polished, and may take a while to understand.</p>
http://ask.sagemath.org/question/8243/how-do-i-create-a-log-plot-of-line-data/?comment=19464#post-id-19464Hey, 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)... Sun, 01 Jul 2012 05:07:46 -0500http://ask.sagemath.org/question/8243/how-do-i-create-a-log-plot-of-line-data/?comment=19464#post-id-19464Comment by Erez for <p>You could rescale the data before you plot it:</p>
<pre><code>sage: data = [(t^2,t^3) for t in srange(1,10,.1)]
sage: L = line2d(data)
sage: L.show(figsize=[5,2])
</code></pre>
<p><img alt="linear plot" src="/upfiles/13117890862047407.png"/></p>
<pre><code>sage: log_data = [(log(x[0]),log(x[1])) for x in data]
sage: M = line2d(log_data)
sage: M.show(figsize=[5,2])
</code></pre>
<p><img alt="log plot" src="/upfiles/13117891387182985.png"/></p>
<p>If you want the tick marks to be logarithmic, the docstring for <code>M.show</code> describes an option for using a matplotlib tick "locator".</p>
<pre><code>sage: from matplotlib import ticker
sage: tloc = lambda m: ticker.LogLocator(subs=[m])
sage: M.show(figsize=[5,2],ticks=(tloc(4),tloc(1)))
</code></pre>
<p><img alt="log plot with log ticks" src="/upfiles/1311789302896444.png"/></p>
<p>To be honest though, I had a lot of trouble using the <code>LogLocator</code> -- it doesn't seem completely polished, and may take a while to understand.</p>
http://ask.sagemath.org/question/8243/how-do-i-create-a-log-plot-of-line-data/?comment=19462#post-id-19462Moreover, 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! Sun, 01 Jul 2012 05:10:50 -0500http://ask.sagemath.org/question/8243/how-do-i-create-a-log-plot-of-line-data/?comment=19462#post-id-19462