Thickness of points in plots

i like this post (click again to cancel)
0
i dont like this post (click again to cancel)

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

asked Feb 21 '12

Andres Caicedo gravatar image Andres Caicedo
37 1 6
http://andrescaicedo.word...

updated Feb 21 '12

Shashank gravatar image Shashank flag of United States
1570 5 22 55

2 Answers:

i like this answer (click again to cancel)
2
i dont like this answer (click again to cancel) Andres Caicedo has selected this answer as correct

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()
link

posted Feb 21 '12

Shashank gravatar image Shashank flag of United States
1570 5 22 55

updated Feb 21 '12

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

Andres Caicedo (Feb 21 '12)

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 (Feb 22 '12)

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 (Feb 23 '12)
i like this answer (click again to cancel)
1
i dont like this answer (click again to cancel)

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.

link

posted Feb 21 '12

DSM gravatar image DSM flag of Canada
4802 12 61 103

updated Feb 21 '12

Many thanks! This is certainly much cleaner.

Andres Caicedo (Feb 21 '12)

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!
[hide preview]

Question tools

Tags:

Stats:

Asked: Feb 21 '12

Seen: 76 times

Last updated: Feb 21 '12

powered by ASKBOT version 0.7.22
Copyright Sage, 2010. Some rights reserved under creative commons license.