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.Thu, 23 Feb 2012 00:06:09 -0600Thickness of points in plotshttp://ask.sagemath.org/question/8732/thickness-of-points-in-plots/How can I change the thickness of points in a graph?
In case it is not clear what I mean, consider the following program, illustrating [Chebyshev's bias](http://en.wikipedia.org/wiki/Chebyshev%27s_bias):
var('N')
N=[]
l=0
k=7
for p in prime_range(10^k+1):
if (p==2):
N.append(0)
else:
if (Mod(p,4)==1):
N.append(N[l]-1)
l=l+1
else:
N.append(N[l]+1)
l=l+1
list_plot(N).show()
(Sorry, I cannot yet upload graphs, but you may quickly run this example and see that:) The dots seem too thick to rally appreciate any fine features of the graph. Is there a way to make the dots smaller (thinner)?
Tue, 21 Feb 2012 10:56:45 -0600http://ask.sagemath.org/question/8732/thickness-of-points-in-plots/Answer by Shashank for <p>How can I change the thickness of points in a graph? </p>
<p>In case it is not clear what I mean, consider the following program, illustrating <a href="http://en.wikipedia.org/wiki/Chebyshev%27s_bias">Chebyshev's bias</a>:</p>
<pre><code>var('N')
N=[]
l=0
k=7
for p in prime_range(10^k+1):
if (p==2):
N.append(0)
else:
if (Mod(p,4)==1):
N.append(N[l]-1)
l=l+1
else:
N.append(N[l]+1)
l=l+1
list_plot(N).show()
</code></pre>
<p>(Sorry, I cannot yet upload graphs, but you may quickly run this example and see that:) The dots seem too thick to rally appreciate any fine features of the graph. Is there a way to make the dots smaller (thinner)? </p>
http://ask.sagemath.org/question/8732/thickness-of-points-in-plots/?answer=13287#post-id-13287By thinkness of points, I assume you mean the size (radius) of the points. Use the argument size to change the size of the points.
list_plot(N,size=1).show()Tue, 21 Feb 2012 11:38:38 -0600http://ask.sagemath.org/question/8732/thickness-of-points-in-plots/?answer=13287#post-id-13287Comment by Andres Caicedo for <p>By thinkness of points, I assume you mean the size (radius) of the points. Use the argument size to change the size of the points.</p>
<pre><code>list_plot(N,size=1).show()
</code></pre>
http://ask.sagemath.org/question/8732/thickness-of-points-in-plots/?comment=20267#post-id-20267Ha! This certainly does it. Thanks! I stubbornly kept trying variations of "thick".Tue, 21 Feb 2012 12:14:56 -0600http://ask.sagemath.org/question/8732/thickness-of-points-in-plots/?comment=20267#post-id-20267Comment by Jason Grout for <p>By thinkness of points, I assume you mean the size (radius) of the points. Use the argument size to change the size of the points.</p>
<pre><code>list_plot(N,size=1).show()
</code></pre>
http://ask.sagemath.org/question/8732/thickness-of-points-in-plots/?comment=20260#post-id-20260Typically, 'size' refers to a size that scales with the data axes, but 'thickness' refers to a size that does not scale. In other words, if something is size=1, then in a plot with larger data limits, it will look smaller, but if something has thickness=1, then its appearance does not change when you change the data limits.Wed, 22 Feb 2012 12:51:05 -0600http://ask.sagemath.org/question/8732/thickness-of-points-in-plots/?comment=20260#post-id-20260Comment by Jason Grout for <p>By thinkness of points, I assume you mean the size (radius) of the points. Use the argument size to change the size of the points.</p>
<pre><code>list_plot(N,size=1).show()
</code></pre>
http://ask.sagemath.org/question/8732/thickness-of-points-in-plots/?comment=20259#post-id-20259I looked into it more, and it seems that for points, the size parameter *is* independent of scaling (so it behaves like the normal thickness parameter). By the way, the size refers to the *area*, not the radius, of the points.Thu, 23 Feb 2012 00:06:09 -0600http://ask.sagemath.org/question/8732/thickness-of-points-in-plots/?comment=20259#post-id-20259Answer by DSM for <p>How can I change the thickness of points in a graph? </p>
<p>In case it is not clear what I mean, consider the following program, illustrating <a href="http://en.wikipedia.org/wiki/Chebyshev%27s_bias">Chebyshev's bias</a>:</p>
<pre><code>var('N')
N=[]
l=0
k=7
for p in prime_range(10^k+1):
if (p==2):
N.append(0)
else:
if (Mod(p,4)==1):
N.append(N[l]-1)
l=l+1
else:
N.append(N[l]+1)
l=l+1
list_plot(N).show()
</code></pre>
<p>(Sorry, I cannot yet upload graphs, but you may quickly run this example and see that:) The dots seem too thick to rally appreciate any fine features of the graph. Is there a way to make the dots smaller (thinner)? </p>
http://ask.sagemath.org/question/8732/thickness-of-points-in-plots/?answer=13289#post-id-13289This isn't an answer to the question -- Shashank already explained that nicely -- but might be helpful anyway. A few points:
var('N')
N=[]
The first statement, `var('N')`, is unnecessary. It makes a symbolic variable called `N` and injects it into the local scope, but you immediately make a list and bind the name `N` to it instead. You only need to use var to make symbolic variables, not to declare things in general (which is one way in which Python is different from many other languages, so it takes some getting used to.)
Next, you don't actually need to keep track of `l`. In Python, you can refer to the last element of a list `L` by `L[-1]`, where the `-1` means "first from the end", and `-2` would mean "second from the end", etc.
sage: a = [3, 10, 5.4]
sage: a
[3, 10, 5.40000000000000]
sage: a[0]
3
sage: a[2]
5.40000000000000
sage: a[-1]
5.40000000000000
sage: a[-2]
10
sage: a[-3]
3
As well, you can use "elif:" instead of chaining else/if pairs deeper and deeper. So one way to condense your code would be into:
N=[]
for p in prime_range(10**k+1):
if p == 2:
N.append(0)
elif p % 4 == 1:
N.append(N[-1]-1)
else:
N.append(N[-1]+1)
where I've used the `%` operator of calling Mod explicitly, because I'm lazy. (There's even a ternary operator, "a if condition else b", so this could be further condensed, but I think it actually looks clearer as is.)
There are even some slick non-loop-based approaches to getting this, but hopefully this helps. In general, if you find yourself needing to keep track of loop indices manually, there's probably a prettier way to do something. Tue, 21 Feb 2012 13:02:21 -0600http://ask.sagemath.org/question/8732/thickness-of-points-in-plots/?answer=13289#post-id-13289Comment by Andres Caicedo for <p>This isn't an answer to the question -- Shashank already explained that nicely -- but might be helpful anyway. A few points:</p>
<pre><code>var('N')
N=[]
</code></pre>
<p>The first statement, <code>var('N')</code>, is unnecessary. It makes a symbolic variable called <code>N</code> and injects it into the local scope, but you immediately make a list and bind the name <code>N</code> to it instead. You only need to use var to make symbolic variables, not to declare things in general (which is one way in which Python is different from many other languages, so it takes some getting used to.)</p>
<p>Next, you don't actually need to keep track of <code>l</code>. In Python, you can refer to the last element of a list <code>L</code> by <code>L[-1]</code>, where the <code>-1</code> means "first from the end", and <code>-2</code> would mean "second from the end", etc.</p>
<pre><code>sage: a = [3, 10, 5.4]
sage: a
[3, 10, 5.40000000000000]
sage: a[0]
3
sage: a[2]
5.40000000000000
sage: a[-1]
5.40000000000000
sage: a[-2]
10
sage: a[-3]
3
</code></pre>
<p>As well, you can use "elif:" instead of chaining else/if pairs deeper and deeper. So one way to condense your code would be into:</p>
<pre><code>N=[]
for p in prime_range(10**k+1):
if p == 2:
N.append(0)
elif p % 4 == 1:
N.append(N[-1]-1)
else:
N.append(N[-1]+1)
</code></pre>
<p>where I've used the <code>%</code> operator of calling Mod explicitly, because I'm lazy. (There's even a ternary operator, "a if condition else b", so this could be further condensed, but I think it actually looks clearer as is.)</p>
<p>There are even some slick non-loop-based approaches to getting this, but hopefully this helps. In general, if you find yourself needing to keep track of loop indices manually, there's probably a prettier way to do something. </p>
http://ask.sagemath.org/question/8732/thickness-of-points-in-plots/?comment=20266#post-id-20266Many thanks! This is certainly much cleaner.Tue, 21 Feb 2012 16:19:21 -0600http://ask.sagemath.org/question/8732/thickness-of-points-in-plots/?comment=20266#post-id-20266