Elegant solution to 'thin out' array and plot line

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

Sometimes I don't know how many points will be in the target array, yet I need to plot a line with markers. If too many points presented, markers on the plot will overlap and an single bold line will be plotted:

line([(x, np.sin(x)) for x in srange(0,np.pi,np.pi/128)], marker='d')

The solution acceptable for me is to 'thin out' input array in order to exclude points, which are too close to each other. My first implementation of such functional is:

def thin_out_array(points, size):
    if len(points) <= size: return points
    g = int(len(points)/size)
    return [p for i,p in enumerate(points) if i % g == 0]

def line(points, thin_out = None, **kwds):
    if thin_out: points = thin_out_array(points, thin_out)
    return sage.plot.line.line(points, **kwds)

So this code gives line with separated markers:

line([(x, np.sin(x)) for x in srange(0,np.pi,np.pi/128)], marker='d', thin_out = 32)

Perhaps, more clear and common way to do such thing is already designed?

asked Jul 16 '11

Eugene gravatar image Eugene
219 1 3 15
i like this answer (click again to cancel)
1
i dont like this answer (click again to cancel)

I'd recommend to plot the data points with sufficiently small markers and a suitable fit on top. This is how data is usually visualized. You can't just drop some of the data, that is very confusing to readers.

link

posted Jul 19 '11

Volker Braun gravatar image Volker Braun
2238 5 22 52

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: Jul 16 '11

Seen: 77 times

Last updated: Jul 19 '11

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