8000 MEP12 on line_collection2.py · matplotlib/matplotlib@fec0d6c · GitHub
[go: up one dir, main page]

Skip to content

Commit fec0d6c

Browse files
committed
MEP12 on line_collection2.py
1 parent 09f2577 commit fec0d6c

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed
Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,37 @@
1-
from pylab import *
1+
import matplotlib.pyplot as plt
2+
import numpy as np
23
from matplotlib.collections import LineCollection
34

45
# In order to efficiently plot many lines in a single set of axes,
56
# Matplotlib has the ability to add the lines all at once. Here is a
67
# simple example showing how it is done.
78

89
N = 50
9-
x = arange(N)
10+
x = np.arange(N)
1011
# Here are many sets of y to plot vs x
1112
ys = [x + i for i in x]
1213

1314
# We need to set the plot limits, they will not autoscale
14-
ax = axes()
15-
ax.set_xlim((amin(x), amax(x)))
16-
ax.set_ylim((amin(amin(ys)), amax(amax(ys))))
15+
ax = plt.axes()
16+
ax.set_xlim((np.amin(x), np.amax(x)))
17+
ax.set_ylim((np.amin(np.amin(ys)), np.amax(np.amax(ys))))
1718

1819
# colors is sequence of rgba tuples
1920
# linestyle is a string or dash tuple. Legal string values are
2021
# solid|dashed|dashdot|dotted. The dash tuple is (offset, onoffseq)
2122
# where onoffseq is an even length tuple of on and off ink in points.
2223
# If linestyle is omitted, 'solid' is used
2324
# See matplotlib.collections.LineCollection for more information
24-
line_segments = LineCollection([list(zip(x, y)) for y in ys], # Make a sequence of x,y pairs
25+
26+
# Make a sequence of x,y pairs
27+
line_segments = LineCollection([list(zip(x, y)) for y in ys],
2528
linewidths=(0.5, 1, 1.5, 2),
2629
linestyles='solid')
2730
line_segments.set_array(x)
2831
ax.add_collection(line_segments)
29-
fig = gcf()
32+
fig = plt.gcf()
3033
axcb = fig.colorbar(line_segments)
3134
axcb.set_label('Line Number')
3235
ax.set_title('Line Collection with mapped colors')
33-
sci(line_segments) # This allows interactive changing of the colormap.
34-
show()
36+
plt.sci(line_segments) # This allows interactive changing of the colormap.
37+
plt.show()

0 commit comments

Comments
 (0)
0