Ask Your Question
0

Thickness of points in plots

asked 2012-02-21 17:56:45 +0100

updated 2012-02-21 19:18:53 +0100

Shashank gravatar image

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

2 Answers

Sort by ยป oldest newest most voted
2

answered 2012-02-21 18:38:38 +0100

Shashank gravatar image

updated 2012-02-21 18:41:45 +0100

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()
edit flag offensive delete link more

Comments

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

Andres Caicedo gravatar imageAndres Caicedo ( 2012-02-21 19:14:56 +0100 )edit

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.

Jason Grout gravatar imageJason Grout ( 2012-02-22 19:51:05 +0100 )edit

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.

Jason Grout gravatar imageJason Grout ( 2012-02-23 07:06:09 +0100 )edit
1

answered 2012-02-21 20:02:21 +0100

DSM gravatar image

updated 2012-02-21 20:04:01 +0100

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

edit flag offensive delete link more

Comments

Many thanks! This is certainly much cleaner.

Andres Caicedo gravatar imageAndres Caicedo ( 2012-02-21 23:19:21 +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

Stats

Asked: 2012-02-21 17:56:45 +0100

Seen: 1,834 times

Last updated: Feb 21 '12