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

Skip to content

MEP10 - refactored hlines and vlines documentation #1795

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 14, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion examples/pylab_examples/README
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
23 changes: 0 additions & 23 deletions examples/pylab_examples/hline_demo.py

This file was deleted.

21 changes: 0 additions & 21 deletions examples/pylab_examples/vline_demo.py

This file was deleted.

36 changes: 36 additions & 0 deletions examples/pylab_examples/vline_hline_demo.py
Original file line number Diff line number Diff line change
@@ -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()
3 changes: 1 addition & 2 deletions examples/tests/backend_driver.py
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down Expand Up @@ -199,7 +199,6 @@
'transoffset.py',
'unicode_demo.py',
'vertical_ticklabels.py',
'vline_demo.py',
'xcorr_demo.py',
'zorder_demo.py',
]
Expand Down
88 changes: 50 additions & 38 deletions lib/matplotlib/axes.py
Original file line number Diff line number Diff line change
Expand Up @@ -3656,37 +3656,39 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid',
"""
Plot horizontal lines.

call signature::
Plot horizontal lines at each `y` from `xmin` to `xmax`.

hlines(y, xmin, xmax, colors='k', linestyles='solid', **kwargs)
Parameters
----------
y : scalar or 1D array_like
y-indexes where to plot the lines.

Plot horizontal lines at each *y* from *xmin* to *xmax*.
xmin, xmax : scalar or 1D array_like
Respective beginning and end of each line. If scalars are
provided, all lines will have same length.

Returns the :class:`~matplotlib.collections.LineCollection`
that was added.
colors : array_like of colors, optional, default: 'k'

Required arguments:
linestyles : ['solid' | 'dashed' | 'dashdot' | 'dotted'], optional

*y*:
a 1-D numpy array or iterable.
label : string, optional, default: ''

*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*.

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
Expand Down Expand Up @@ -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
-------
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have the contents of this now been included directly?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nope, this is lost. Using this trick doesn't work (it is not rendered properly), and numpydoc has no way to do introspection to spot that these are linecollection kwargs.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know that whether to continue to include these inline was controversial -- but I tend to fall on the side of not duplicating this information everywhere. If we do that, though, we need a clear link to the LineProperties class, and my suggested change for the Returns section above does that.

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)
Expand Down Expand Up @@ -8322,8 +8336,6 @@ def hist(self, x, bins=10, range=None, normed=False, weights=None,
mlast[:] = m
n.append(m)



if cumulative:
slc = slice(None)
if cbook.is_numlike(cumulative) and cumulative < 0:
Expand Down Expand Up @@ -8405,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 for the lowest bin
Expand Down