# 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:

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

edit retag close merge delete

Sort by » oldest newest most voted 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.

list_plot(N,size=1).show()

more

Ha! This certainly does it. Thanks! I stubbornly kept trying variations of "thick".

Typically, '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.

I 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. This 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
3
sage: a
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.

more