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

Skip to content

Commit 333c801

Browse files
committed
unified hlines and vlines
svn path=/trunk/matplotlib/; revision=1701
1 parent 15559d9 commit 333c801

3 files changed

Lines changed: 30 additions & 5 deletions

File tree

API_CHANGES

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
API Changes in matplotlib-0.84
22

3+
Unified argument handling between hlines and vlines. Both now
4+
take optionally a fmt argument (as in plot) and a keyword args
5+
that can be passed onto Line2D.
6+
37
Removed all references to "data clipping" in rc and lines.py since
48
these were not used and not optimized. I'm sure they'll be
59
resurrected later with a better implementation when needed.

examples/vline_demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def f(t):
1414
nse = multiply(normal(0.0, 0.3, t.shape), s)
1515

1616
plot(t, s+nse, 'b^')
17-
vlines(t, [0], s, color='k')
17+
vlines(t, [0], s, fmt='k-')
1818
xlabel('time (s)')
1919
title('Comparison of model with data')
2020
show()

lib/matplotlib/axes.py

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1900,7 +1900,7 @@ def in_axes(self, xwin, ywin):
19001900
'return True is the point xwin, ywin (display coords) are in the Axes'
19011901
return self.bbox.contains(xwin, ywin)
19021902

1903-
def hlines(self, y, xmin, xmax, fmt='k-'):
1903+
def hlines(self, y, xmin, xmax, fmt='k-', **kwargs):
19041904
"""
19051905
HLINES(y, xmin, xmax, fmt='k-')
19061906
@@ -1909,11 +1909,18 @@ def hlines(self, y, xmin, xmax, fmt='k-'):
19091909
respective values are constant, else the widths of the lines are
19101910
determined by xmin and xmax
19111911
1912+
fmt is a plot format string, eg 'g--'
1913+
1914+
kwargs are matplotlib.lines.Line2D kwargs
1915+
19121916
Returns a list of line instances that were added
19131917
"""
19141918
linestyle, marker, color = _process_plot_format(fmt)
19151919

1916-
# todo: fix me for y is scalar and xmin and xmax are iterable
1920+
1921+
if not iterable(y): y = [y]
1922+
if not iterable(xmin): xmin = [xmin]
1923+
if not iterable(xmax): xmax = [xmax]
19171924
y = asarray(y)
19181925
xmin = asarray(xmin)
19191926
xmax = asarray(xmax)
@@ -1933,6 +1940,7 @@ def hlines(self, y, xmin, xmax, fmt='k-'):
19331940
line = Line2D(
19341941
[thisMin, thisMax], [thisY, thisY],
19351942
color=color, linestyle=linestyle, marker=marker,
1943+
**kwargs
19361944
)
19371945
self.add_line( line )
19381946
lines.append(line)
@@ -3562,7 +3570,7 @@ def toggle_log_lineary(self):
35623570
if funcy==LOG10: self.set_yscale('linear')
35633571
elif funcy==IDENTITY: self.set_yscale('log')
35643572

3565-
def vlines(self, x, ymin, ymax, color='k'):
3573+
def vlines(self, x, ymin, ymax, fmt='k-', **kwargs):
35663574
"""
35673575
VLINES(x, ymin, ymax, color='k')
35683576
@@ -3571,8 +3579,19 @@ def vlines(self, x, ymin, ymax, color='k'):
35713579
respective values are constant, else the heights of the lines are
35723580
determined by ymin and ymax
35733581
3582+
3583+
fmt is a plot format string, eg 'g--'
3584+
3585+
kwargs are matplotlib.lines.Line2D kwargs
3586+
35743587
Returns a list of lines that were added
35753588
"""
3589+
linestyle, marker, color = _process_plot_format(fmt)
3590+
3591+
3592+
if not iterable(x): x = [x]
3593+
if not iterable(ymin): ymin = [ymin]
3594+
if not iterable(ymax): ymax = [ymax]
35763595
x = asarray(x)
35773596
ymin = asarray(ymin)
35783597
ymax = asarray(ymax)
@@ -3592,7 +3611,9 @@ def vlines(self, x, ymin, ymax, color='k'):
35923611
lines = []
35933612
for thisX, thisY in zip(x,Y):
35943613
line = Line2D(
3595-
[thisX, thisX], thisY, color=color, linestyle='-',
3614+
[thisX, thisX], thisY,
3615+
color=color, linestyle=linestyle, marker=marker,
3616+
**kwargs
35963617
)
35973618
self.add_line(line)
35983619
lines.append(line)

0 commit comments

Comments
 (0)