|
| 1 | +from pylab import * |
| 2 | +from matplotlib.collections import LineCollection |
| 3 | +from matplotlib.colors import ColorConverter |
| 4 | +colorConverter = ColorConverter() |
| 5 | + |
| 6 | +# In order to efficiently plot many lines in a single set of axes, |
| 7 | +# Matplotlib has the ability to add the lines all at once. Here is a |
| 8 | +# simple example showing how it is done. |
| 9 | + |
| 10 | +x = arange(200) |
| 11 | +# Here are many sets of y to plot vs x |
| 12 | +ys = [x+i for i in x] |
| 13 | + |
| 14 | +# We need to set the plot limits, the will not autoscale |
| 15 | +ax = axes() |
| 16 | +ax.set_xlim((amin(x),amax(x))) |
| 17 | +ax.set_ylim((amin(amin(ys)),amax(amax(ys)))) |
| 18 | + |
| 19 | +# colors is sequence of rgba tuples |
| 20 | +# linestyle is a string or dash tuple. Legal string values are |
| 21 | +# solid|dashed|dashdot|dotted. The dash tuple is (offset, onoffseq) |
| 22 | +# where onoffseq is an even length tuple of on and off ink in points. |
| 23 | +# If linestyle is omitted, 'solid' is used |
| 24 | +# See matplotlib.collections.LineCollection for more information |
| 25 | +line_segments = LineCollection([zip(x,y) for y in ys], # Make a sequence of x,y pairs |
| 26 | + linewidths = (0.5,1,1.5,2), |
| 27 | + colors = [colorConverter.to_rgba(i) \ |
| 28 | + for i in ('b','g','r','c','m','y','k')], |
| 29 | + linestyle = 'solid') |
| 30 | +ax.add_collection(line_segments) |
| 31 | +show() |
| 32 | + |
| 33 | + |
0 commit comments