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.Tue, 14 May 2019 16:12:49 -0500Plot points in logloghttp://ask.sagemath.org/question/46482/plot-points-in-loglog/Hi I'm trying to plot a function with loglog scaling. However the result seems to have very few plot points. I'm using Sage 8.7 on Windows.
![image description](https://i.ibb.co/5BNwDCk/Sage-Log-Log.png)
Is this a bug or am I doing something wrong?
Cheers!Fri, 10 May 2019 05:32:54 -0500http://ask.sagemath.org/question/46482/plot-points-in-loglog/Comment by Iguananaut for <p>Hi I'm trying to plot a function with loglog scaling. However the result seems to have very few plot points. I'm using Sage 8.7 on Windows.</p>
<p><img alt="image description" src="https://i.ibb.co/5BNwDCk/Sage-Log-Log.png"></p>
<p>Is this a bug or am I doing something wrong?</p>
<p>Cheers!</p>
http://ask.sagemath.org/question/46482/plot-points-in-loglog/?comment=46484#post-id-46484I don't know an immediate answer off the top of my head, but it looks like it has to do with how the plotted points are being sampled. For whatever reason it's not finding your inflection point and adding extra points around it to make it look smoother; instead you just get this sharp inflection. BTW, it would help if you posted the text of your code in the question so it can easily be copy/pasted.Fri, 10 May 2019 12:08:11 -0500http://ask.sagemath.org/question/46482/plot-points-in-loglog/?comment=46484#post-id-46484Answer by slelievre for <p>Hi I'm trying to plot a function with loglog scaling. However the result seems to have very few plot points. I'm using Sage 8.7 on Windows.</p>
<p><img alt="image description" src="https://i.ibb.co/5BNwDCk/Sage-Log-Log.png"></p>
<p>Is this a bug or am I doing something wrong?</p>
<p>Cheers!</p>
http://ask.sagemath.org/question/46482/plot-points-in-loglog/?answer=46488#post-id-46488It would seem plots in log scale use a sampling done in the non-log scale...
Since plots only 200 plot points by default, the sampling in non-log scale
means that for a log-scale plot, most plot points are near the end, and
they are very scarce in the first 3/4 of the plot.
A workaround, as suggested in @Iguananaut's answer, is to use more plot points.
Using 800 plot points already gives a much smoother curve here:
sage: tau = RDF.pi()*2
sage: out2 = lambda r, c: lambda f: ~(1 + (tau*f*r*c)^2)
sage: plot(out2(15, 2.7e-9), (10, 500e6), scale='loglog', plot_points=800)
Launched png viewer for Graphics object consisting of 1 graphics primitive
There was a problem I thought looked similar: the x-range and y-range for
a plot are chosen slightly wider than the actual range of x-values and y-values
that occur in the plot, and sometimes in log scale it looks like this "slightly
wider" is chosen in non-log scale, giving a wrong aspect. See
- [Ask Sage question 26637: Plot boxes have jumpy xy ranges in log scale](https://ask.sagemath.org/question/26637)Sat, 11 May 2019 15:32:52 -0500http://ask.sagemath.org/question/46482/plot-points-in-loglog/?answer=46488#post-id-46488Comment by slelievre for <p>It would seem plots in log scale use a sampling done in the non-log scale...</p>
<p>Since plots only 200 plot points by default, the sampling in non-log scale
means that for a log-scale plot, most plot points are near the end, and
they are very scarce in the first 3/4 of the plot.</p>
<p>A workaround, as suggested in <a href="/users/23374/iguananaut/">@Iguananaut</a>'s answer, is to use more plot points.</p>
<p>Using 800 plot points already gives a much smoother curve here:</p>
<pre><code>sage: tau = RDF.pi()*2
sage: out2 = lambda r, c: lambda f: ~(1 + (tau*f*r*c)^2)
sage: plot(out2(15, 2.7e-9), (10, 500e6), scale='loglog', plot_points=800)
Launched png viewer for Graphics object consisting of 1 graphics primitive
</code></pre>
<p>There was a problem I thought looked similar: the x-range and y-range for
a plot are chosen slightly wider than the actual range of x-values and y-values
that occur in the plot, and sometimes in log scale it looks like this "slightly
wider" is chosen in non-log scale, giving a wrong aspect. See</p>
<ul>
<li><a href="https://ask.sagemath.org/question/26637">Ask Sage question 26637: Plot boxes have jumpy xy ranges in log scale</a></li>
</ul>
http://ask.sagemath.org/question/46482/plot-points-in-loglog/?comment=46523#post-id-46523This should definitely be fixed. Maybe as part of
- [Sage Trac ticket 15320: plot_semilogx(1/log(x),10,10^15) should look like plot(1/x,1,15)](https://trac.sagemath.org/ticket/15320)Tue, 14 May 2019 16:12:49 -0500http://ask.sagemath.org/question/46482/plot-points-in-loglog/?comment=46523#post-id-46523Comment by Iguananaut for <p>It would seem plots in log scale use a sampling done in the non-log scale...</p>
<p>Since plots only 200 plot points by default, the sampling in non-log scale
means that for a log-scale plot, most plot points are near the end, and
they are very scarce in the first 3/4 of the plot.</p>
<p>A workaround, as suggested in <a href="/users/23374/iguananaut/">@Iguananaut</a>'s answer, is to use more plot points.</p>
<p>Using 800 plot points already gives a much smoother curve here:</p>
<pre><code>sage: tau = RDF.pi()*2
sage: out2 = lambda r, c: lambda f: ~(1 + (tau*f*r*c)^2)
sage: plot(out2(15, 2.7e-9), (10, 500e6), scale='loglog', plot_points=800)
Launched png viewer for Graphics object consisting of 1 graphics primitive
</code></pre>
<p>There was a problem I thought looked similar: the x-range and y-range for
a plot are chosen slightly wider than the actual range of x-values and y-values
that occur in the plot, and sometimes in log scale it looks like this "slightly
wider" is chosen in non-log scale, giving a wrong aspect. See</p>
<ul>
<li><a href="https://ask.sagemath.org/question/26637">Ask Sage question 26637: Plot boxes have jumpy xy ranges in log scale</a></li>
</ul>
http://ask.sagemath.org/question/46482/plot-points-in-loglog/?comment=46503#post-id-46503"It would seem plots in log scale use a sampling done in the non-log scale..." I wondered if that might be the case myself. If so, should we open a ticket for this? Seems buggy to me.Mon, 13 May 2019 10:35:02 -0500http://ask.sagemath.org/question/46482/plot-points-in-loglog/?comment=46503#post-id-46503Comment by LeChuck42 for <p>It would seem plots in log scale use a sampling done in the non-log scale...</p>
<p>Since plots only 200 plot points by default, the sampling in non-log scale
means that for a log-scale plot, most plot points are near the end, and
they are very scarce in the first 3/4 of the plot.</p>
<p>A workaround, as suggested in <a href="/users/23374/iguananaut/">@Iguananaut</a>'s answer, is to use more plot points.</p>
<p>Using 800 plot points already gives a much smoother curve here:</p>
<pre><code>sage: tau = RDF.pi()*2
sage: out2 = lambda r, c: lambda f: ~(1 + (tau*f*r*c)^2)
sage: plot(out2(15, 2.7e-9), (10, 500e6), scale='loglog', plot_points=800)
Launched png viewer for Graphics object consisting of 1 graphics primitive
</code></pre>
<p>There was a problem I thought looked similar: the x-range and y-range for
a plot are chosen slightly wider than the actual range of x-values and y-values
that occur in the plot, and sometimes in log scale it looks like this "slightly
wider" is chosen in non-log scale, giving a wrong aspect. See</p>
<ul>
<li><a href="https://ask.sagemath.org/question/26637">Ask Sage question 26637: Plot boxes have jumpy xy ranges in log scale</a></li>
</ul>
http://ask.sagemath.org/question/46482/plot-points-in-loglog/?comment=46500#post-id-46500Yes, I tried displaying the plot points with
plot(out(15, 2.7e-9)^2, (10, 500e6), scale='loglog', markers="+")
and there are lots of points in the section > 10^7 suggesting the selection of points is done in non-log scale. I think this is really confusing and probably should be fixed in a future release.
Marked as answer, because of this. But thanks to @Iguananaut for the workaround!Mon, 13 May 2019 03:56:21 -0500http://ask.sagemath.org/question/46482/plot-points-in-loglog/?comment=46500#post-id-46500Answer by Iguananaut for <p>Hi I'm trying to plot a function with loglog scaling. However the result seems to have very few plot points. I'm using Sage 8.7 on Windows.</p>
<p><img alt="image description" src="https://i.ibb.co/5BNwDCk/Sage-Log-Log.png"></p>
<p>Is this a bug or am I doing something wrong?</p>
<p>Cheers!</p>
http://ask.sagemath.org/question/46482/plot-points-in-loglog/?answer=46485#post-id-46485I was able to obtain a reasonably nice plot with:
plot(out(15, 2.7e-9), (10, 500e6), scale='semilogx', plot_points=2000)
![image description](/upfiles/15575086632992567.png)
Another way you could do it is break it up into multiple plots, with one plot adding more points just around the inflection point, like:
f_0 = out(15, 2.7e-9)
P = plot(f_0, (10, 3e5), scale='semilogx') # Just eyeballing it
P += plot(f_0, (3e5, 3e6), scale='semilogx')
P += plot(f_0, (3e6, 5e8))
P
![image description](/upfiles/15575089241614525.png)
which looks a tiny bit smoother.
Regardless, it could be nice if the automatic interpolation were better in this case. It's possible some other parameters could be adjusted to improve it but I'm not sure.Fri, 10 May 2019 12:23:11 -0500http://ask.sagemath.org/question/46482/plot-points-in-loglog/?answer=46485#post-id-46485Comment by Iguananaut for <p>I was able to obtain a reasonably nice plot with:</p>
<pre><code>plot(out(15, 2.7e-9), (10, 500e6), scale='semilogx', plot_points=2000)
</code></pre>
<p><img alt="image description" src="/upfiles/15575086632992567.png"></p>
<p>Another way you could do it is break it up into multiple plots, with one plot adding more points just around the inflection point, like:</p>
<pre><code>f_0 = out(15, 2.7e-9)
P = plot(f_0, (10, 3e5), scale='semilogx') # Just eyeballing it
P += plot(f_0, (3e5, 3e6), scale='semilogx')
P += plot(f_0, (3e6, 5e8))
P
</code></pre>
<p><img alt="image description" src="/upfiles/15575089241614525.png"></p>
<p>which looks a tiny bit smoother.</p>
<p>Regardless, it could be nice if the automatic interpolation were better in this case. It's possible some other parameters could be adjusted to improve it but I'm not sure.</p>
http://ask.sagemath.org/question/46482/plot-points-in-loglog/?comment=46486#post-id-46486I'll also add that since most of that initial level part is not very interesting you might also consider just cropping the plot by having the x-axis start around 10e4, 10e5 or so...Fri, 10 May 2019 12:24:26 -0500http://ask.sagemath.org/question/46482/plot-points-in-loglog/?comment=46486#post-id-46486