# Elegant solution to 'thin out' array and plot line

 0 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 229 ● 1 ● 5 ● 19

 1 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. posted Jul 19 '11 Volker Braun 2666 ● 9 ● 24 ● 59

[hide preview]