Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1489130

Browse files
committed
Added step plot based on patch by Manuel Metz
svn path=/trunk/matplotlib/; revision=3737
1 parent 35a9413 commit 1489130

5 files changed

Lines changed: 141 additions & 42 deletions

File tree

boilerplate.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,7 @@ def %(func)s(*args, **kwargs):
8080
'specgram',
8181
'spy',
8282
'stem',
83+
'step',
8384
'vlines',
8485
'quiver',
8586
'quiverkey',

examples/masked_demo.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
break the line at the data gaps.
77
'''
88

9-
import matplotlib.numerix.ma as M
9+
import matplotlib.numerix.npyma as ma
1010
from pylab import *
1111

12-
x = M.arange(0, 2*pi, 0.02)
13-
y = M.sin(x)
12+
x = ma.arange(0, 2*pi, 0.02)
13+
y = ma.sin(x)
1414
y1 = sin(2*x)
1515
y2 = sin(3*x)
16-
ym1 = M.masked_where(y1 > 0.5, y1)
17-
ym2 = M.masked_where(y2 < -0.5, y2)
16+
ym1 = ma.masked_where(y1 > 0.5, y1)
17+
ym2 = ma.masked_where(y2 < -0.5, y2)
1818

1919
lines = plot(x, y, 'r', x, ym1, 'g', x, ym2, 'bo')
2020
setp(lines[0], linewidth = 4)

examples/step_demo.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import numpy as npy
2+
from pylab import *
3+
4+
x = npy.arange(1, 7, 0.4)
5+
y0 = npy.sin(x)
6+
y = y0.copy() + 2.5
7+
8+
step(x, y, label='pre (default)')
9+
10+
y -= 0.5
11+
step(x, y, where='mid', label='mid')
12+
13+
y -= 0.5
14+
step(x, y, where='post', label='post')
15+
16+
y = npy.ma.masked_where((y0>-0.15)&(y0<0.15), y - 0.5)
17+
step(x,y, label='masked (pre)')
18+
19+
legend()
20+
21+
xlim(0, 7)
22+
ylim(-0.5, 4)
23+
24+
show()

lib/matplotlib/axes.py

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2964,6 +2964,58 @@ def get_handles():
29642964

29652965
#### Specialized plotting
29662966

2967+
def step(self, x, y, *args, **kwargs):
2968+
'''
2969+
step(x, y, *args, **kwargs)
2970+
2971+
x and y must be 1-D sequences, and it is assumed, but not checked,
2972+
that x is uniformly increasing.
2973+
2974+
Make a step plot. The args and keyword args to step are the same
2975+
as the args to plot. See help plot for more info.
2976+
2977+
Additional keyword args for step:
2978+
2979+
* where: can be 'pre', 'post' or 'mid'; if 'pre', the
2980+
interval from x[i] to x[i+1] has level y[i];
2981+
if 'post', that interval has level y[i+1];
2982+
and if 'mid', the jumps in y occur half-way
2983+
between the x-values. Default is 'pre'.
2984+
'''
2985+
2986+
where = kwargs.pop('where', 'pre')
2987+
2988+
if not cbook.iterable(x):
2989+
x = ma.array([x], dtype=npy.float_)
2990+
if not cbook.iterable(y):
2991+
y = ma.array([y], dtype=npy.float_)
2992+
2993+
if where=='pre':
2994+
x2 = ma.zeros((2*len(x)-1,), npy.float_)
2995+
y2 = ma.zeros((2*len(y)-1,), npy.float_)
2996+
2997+
x2[0::2], x2[1::2] = x, x[:-1]
2998+
y2[0::2], y2[1:-1:2] = y, y[1:]
2999+
3000+
elif where=='post':
3001+
x2 = ma.zeros((2*len(x)-1,), npy.float_)
3002+
y2 = ma.zeros((2*len(y)-1,), npy.float_)
3003+
3004+
x2[::2], x2[1:-1:2] = x, x[1:]
3005+
y2[0::2], y2[1::2] = y, y[:-1]
3006+
3007+
elif where=='mid':
3008+
x2 = ma.zeros((2*len(x),), npy.float_)
3009+
y2 = ma.zeros((2*len(y),), npy.float_)
3010+
3011+
x2[1:-1:2] = 0.5*(x[:-1]+x[1:])
3012+
x2[2::2] = 0.5*(x[:-1]+x[1:])
3013+
x2[0], x2[-1] = x[0], x[-1]
3014+
3015+
y2[0::2], y2[1::2] = y, y
3016+
3017+
return self.plot(x2, y2, *args, **kwargs)
3018+
29673019

29683020
def bar(self, left, height, width=0.8, bottom=None,
29693021
color=None, edgecolor=None, linewidth=None,

0 commit comments

Comments
 (0)