Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #1795 from NelleV/MEP10_hvlines

MEP10 - refactored hlines and vlines documentation
  • Loading branch information...
commit 9690232fe8ad1d1dfda9d0a64498f14b48e58c04 2 parents 946ffad + 0de3de8
@mdboom mdboom authored
View
2  examples/pylab_examples/README
@@ -13,7 +13,7 @@ Here are some demos of how to use the matplotlib.
-- subplot_demo.py - how to do multiple axes on a single plot
--- vline_demo.py - working with straight lines
+-- vline_hline_demo.py - working with straight lines
-- stock_demo.py - working with large datasets. Click on the plot and
launch the navigation tool; wheel mouse over the navigation
View
23 examples/pylab_examples/hline_demo.py
@@ -1,23 +0,0 @@
-#!/usr/bin/env python
-import numpy as np
-import matplotlib.pyplot as plt
-
-def f(t):
- s1 = np.sin(2*np.pi*t)
- e1 = np.exp(-t)
- return np.absolute((s1*e1))+.05
-
-
-t = np.arange(0.0, 5.0, 0.1)
-s = f(t)
-nse = np.random.normal(0.0, 0.3, t.shape) * s
-
-
-plt.plot(s+nse, t, 'b^')
-plt.hlines(t, [0], s, lw=2)
-plt.xlabel('time (s)')
-plt.title('Comparison of model with data')
-
-plt.xlim(xmin=0)
-plt.show()
-
View
21 examples/pylab_examples/vline_demo.py
@@ -1,21 +0,0 @@
-#!/usr/bin/env python
-from matplotlib.pyplot import *
-from numpy import sin, exp, absolute, pi, arange
-from numpy.random import normal
-
-def f(t):
- s1 = sin(2*pi*t)
- e1 = exp(-t)
- return absolute((s1*e1))+.05
-
-
-t = arange(0.0, 5.0, 0.1)
-s = f(t)
-nse = normal(0.0, 0.3, t.shape) * s
-
-plot(t, s+nse, 'b^')
-vlines(t, [0], s)
-xlabel('time (s)')
-title('Comparison of model with data')
-show()
-
View
36 examples/pylab_examples/vline_hline_demo.py
@@ -0,0 +1,36 @@
+#!/usr/bin/env python
+
+"""
+Small demonstration of the hlines and vlines plots.
+"""
+
+from matplotlib import pyplot as plt
+from numpy import sin, exp, absolute, pi, arange
+from numpy.random import normal
+
+
+def f(t):
+ s1 = sin(2 * pi * t)
+ e1 = exp(-t)
+ return absolute((s1 * e1)) + .05
+
+
+t = arange(0.0, 5.0, 0.1)
+s = f(t)
+nse = normal(0.0, 0.3, t.shape) * s
+
+fig = plt.figure(figsize=(12, 6))
+vax = fig.add_subplot(121)
+hax = fig.add_subplot(122)
+
+vax.plot(t, s + nse, 'b^')
+vax.vlines(t, [0], s)
+vax.set_xlabel('time (s)')
+vax.set_title('Vertical lines demo')
+
+hax.plot(s + nse, t, 'b^')
+hax.hlines(t, [0], s, lw=2)
+hax.set_xlabel('time (s)')
+hax.set_title('Horizontal lines demo')
+
+plt.show()
View
3  examples/tests/backend_driver.py
@@ -113,7 +113,7 @@
'hist_colormapped.py',
'histogram_demo.py',
'histogram_demo_extended.py',
- 'hline_demo.py',
+ 'vline_hline_demo.py',
'image_clip_path.py',
'image_demo.py',
@@ -199,7 +199,6 @@
'transoffset.py',
'unicode_demo.py',
'vertical_ticklabels.py',
- 'vline_demo.py',
'xcorr_demo.py',
'zorder_demo.py',
]
View
86 lib/matplotlib/axes.py
@@ -3656,37 +3656,39 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid',
"""
Plot horizontal lines.
- call signature::
-
- hlines(y, xmin, xmax, colors='k', linestyles='solid', **kwargs)
+ Plot horizontal lines at each `y` from `xmin` to `xmax`.
- Plot horizontal lines at each *y* from *xmin* to *xmax*.
+ Parameters
+ ----------
+ y : scalar or 1D array_like
+ y-indexes where to plot the lines.
- Returns the :class:`~matplotlib.collections.LineCollection`
- that was added.
+ xmin, xmax : scalar or 1D array_like
+ Respective beginning and end of each line. If scalars are
+ provided, all lines will have same length.
- Required arguments:
+ colors : array_like of colors, optional, default: 'k'
- *y*:
- a 1-D numpy array or iterable.
+ linestyles : ['solid' | 'dashed' | 'dashdot' | 'dotted'], optional
- *xmin* and *xmax*:
- can be scalars or ``len(x)`` numpy arrays. If they are
- scalars, then the respective values are constant, else the
- widths of the lines are determined by *xmin* and *xmax*.
+ label : string, optional, default: ''
- Optional keyword arguments:
+ Returns
+ -------
+ lines : `~matplotlib.collections.LineCollection`
- *colors*:
- a line collections color argument, either a single color
- or a ``len(y)`` list of colors
+ Other parameters
+ ----------------
+ kwargs : `~matplotlib.collections.LineCollection` properties.
- *linestyles*:
- [ 'solid' | 'dashed' | 'dashdot' | 'dotted' ]
+ See also
+ --------
+ vlines : vertical lines
- **Example:**
+ Examples
+ --------
+ .. plot:: mpl_examples/pylab_examples/vline_hline_demo.py
- .. plot:: mpl_examples/pylab_examples/hline_demo.py
"""
# We do the conversion first since not all unitized data is uniform
@@ -3743,27 +3745,39 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid',
"""
Plot vertical lines.
- Call signature::
+ Plot vertical lines at each `x` from `ymin` to `ymax`.
- vlines(x, ymin, ymax, color='k', linestyles='solid')
+ Parameters
+ ----------
+ x : scalar or 1D array_like
+ x-indexes where to plot the lines.
- Plot vertical lines at each *x* from *ymin* to *ymax*. *ymin*
- or *ymax* can be scalars or len(*x*) numpy arrays. If they are
- scalars, then the respective values are constant, else the
- heights of the lines are determined by *ymin* and *ymax*.
+ xmin, xmax : scalar or 1D array_like
+ Respective beginning and end of each line. If scalars are
+ provided, all lines will have same length.
- *colors* :
- A line collection's color args, either a single color
- or a ``len(x)`` list of colors
+ colors : array_like of colors, optional, default: 'k'
- *linestyles* : [ 'solid' | 'dashed' | 'dashdot' | 'dotted' ]
+ linestyles : ['solid' | 'dashed' | 'dashdot' | 'dotted'], optional
- Returns the :class:`matplotlib.collections.LineCollection`
- that was added.
+ label : string, optional, default: ''
- kwargs are :class:`~matplotlib.collections.LineCollection` properties:
+ Returns
+ -------
+ lines : `~matplotlib.collections.LineCollection`
+
+ Other parameters
+ ----------------
+ kwargs : `~matplotlib.collections.LineCollection` properties.
+
+ See also
+ --------
+ hlines : horizontal lines
+
+ Examples
+ ---------
+ .. plot:: mpl_examples/pylab_examples/vline_hline_demo.py
- %(LineCollection)s
"""
self._process_unit_info(xdata=x, ydata=[ymin, ymax], kwargs=kwargs)
@@ -8403,7 +8417,7 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
# For normed data, set to log base * minimum data value
# (gives 1 full tick-label unit for the lowest filled bin)
ndata = np.array(n)
- minimum = (np.min(ndata[ndata>0])) / logbase
+ minimum = (np.min(ndata[ndata > 0])) / logbase
else:
# For non-normed data, set the min to log base,
# again so that there is 1 full tick-label unit

0 comments on commit 9690232

Please sign in to comment.
Something went wrong with that request. Please try again.