Ask Your Question
0

Elegant solution to 'thin out' array and plot line

asked 2011-07-16 15:48:10 +0200

Eugene gravatar image

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2011-07-19 12:27:10 +0200

Volker Braun gravatar image

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.

edit flag offensive delete link more

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: 2011-07-16 15:48:10 +0200

Seen: 400 times

Last updated: Jul 19 '11