From 4c23c3819c015afe8746cd5aeb5ef586bcd4fba2 Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Thu, 28 Feb 2013 09:40:49 +0100 Subject: [PATCH 1/4] MEP10 - refactored hlines and vlines documentation --- lib/matplotlib/axes.py | 83 ++++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 40 deletions(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index e70d4d28da02..75c7c8b89a57 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -3656,37 +3656,36 @@ 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*. - - Returns the :class:`~matplotlib.collections.LineCollection` - that was added. - - Required arguments: + Plot horizontal lines at each `y` from `xmin` to `xmax`. - *y*: - a 1-D numpy array or iterable. + Parameters + ---------- + y : scalar or 1D array like + y-indexes where to plot the lines. - *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*. + xmin, xmax : scalar or 1D array like + Respective beginning and end of each line. If scalars are + provided, all lines will have same length. - Optional keyword arguments: + colors : a line collections color argument, either a single color + or a list of colors - *colors*: - a line collections color argument, either a single color - or a ``len(y)`` list of colors + linestyles : ['solid' | 'dashed' | 'dashdot' | 'dotted'], optional, + default : 'solid' - *linestyles*: - [ 'solid' | 'dashed' | 'dashdot' | 'dotted' ] + label : string, optional, default: '' - **Example:** + Returns + ------- + :class:`~matplotlib.collections.LineCollection` + Example + -------- .. plot:: mpl_examples/pylab_examples/hline_demo.py + + See also + -------- + vlines : horizontal lines """ # We do the conversion first since not all unitized data is uniform @@ -3743,27 +3742,33 @@ 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 : a line collections color argument, either a single color + or a list of colors - *linestyles* : [ 'solid' | 'dashed' | 'dashdot' | 'dotted' ] + linestyles : ['solid' | 'dashed' | 'dashdot' | 'dotted'], optional, + default : 'solid' - Returns the :class:`matplotlib.collections.LineCollection` - that was added. + label : string, optional, default: '' - kwargs are :class:`~matplotlib.collections.LineCollection` properties: + Returns + ------- + :class:`~matplotlib.collections.LineCollection` + + See also + -------- + hlines : horizontal lines - %(LineCollection)s """ self._process_unit_info(xdata=x, ydata=[ymin, ymax], kwargs=kwargs) @@ -8322,8 +8327,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: @@ -8405,7 +8408,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 From 58458de1a5a849a2b40751d417bd3412a1074ff2 Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Thu, 28 Feb 2013 09:56:48 +0100 Subject: [PATCH 2/4] Modified hline and vline examples to have only one file and linked them to the documentation --- examples/pylab_examples/README | 2 +- examples/pylab_examples/hline_demo.py | 23 ------------- examples/pylab_examples/vline_demo.py | 21 ------------ examples/pylab_examples/vline_hline_demo.py | 36 +++++++++++++++++++++ examples/tests/backend_driver.py | 3 +- lib/matplotlib/axes.py | 6 +++- 6 files changed, 43 insertions(+), 48 deletions(-) delete mode 100755 examples/pylab_examples/hline_demo.py delete mode 100644 examples/pylab_examples/vline_demo.py create mode 100644 examples/pylab_examples/vline_hline_demo.py diff --git a/examples/pylab_examples/README b/examples/pylab_examples/README index 231b7b4ba9aa..e45e071ea9ce 100644 --- a/examples/pylab_examples/README +++ b/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 diff --git a/examples/pylab_examples/hline_demo.py b/examples/pylab_examples/hline_demo.py deleted file mode 100755 index 8d02cca3e8f5..000000000000 --- a/examples/pylab_examples/hline_demo.py +++ /dev/null @@ -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() - diff --git a/examples/pylab_examples/vline_demo.py b/examples/pylab_examples/vline_demo.py deleted file mode 100644 index 98b512f50aec..000000000000 --- a/examples/pylab_examples/vline_demo.py +++ /dev/null @@ -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() - diff --git a/examples/pylab_examples/vline_hline_demo.py b/examples/pylab_examples/vline_hline_demo.py new file mode 100644 index 000000000000..fe85582a527d --- /dev/null +++ b/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() diff --git a/examples/tests/backend_driver.py b/examples/tests/backend_driver.py index 9f1c28bb7606..61bb756088ea 100755 --- a/examples/tests/backend_driver.py +++ b/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', ] diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index 75c7c8b89a57..672dbc4bdb74 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -3681,7 +3681,7 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid', Example -------- - .. plot:: mpl_examples/pylab_examples/hline_demo.py + .. plot:: mpl_examples/pylab_examples/vline_hline_demo.py See also -------- @@ -3765,6 +3765,10 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid', ------- :class:`~matplotlib.collections.LineCollection` + Example + ------- + .. plot:: mpl_examples/pylab_examples/vline_hline_demo.py + See also -------- hlines : horizontal lines From ec54a0bb456cee56e80e56691a5c91c854bf5688 Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Thu, 28 Feb 2013 11:57:55 +0100 Subject: [PATCH 3/4] DOC mentions kwargs in vlines and hlines --- lib/matplotlib/axes.py | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index 672dbc4bdb74..a14fe8681998 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -3667,25 +3667,27 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid', Respective beginning and end of each line. If scalars are provided, all lines will have same length. - colors : a line collections color argument, either a single color - or a list of colors + colors : array_like of colors, optional, default: 'k' - linestyles : ['solid' | 'dashed' | 'dashdot' | 'dotted'], optional, - default : 'solid' + linestyles : ['solid' | 'dashed' | 'dashdot' | 'dotted'], optional label : string, optional, default: '' Returns ------- - :class:`~matplotlib.collections.LineCollection` + matplotlib.collections.LineCollection - Example - -------- + Other parameters + ---------------- + kwargs correspond to matplotlib.collections.LineCollection properties. + + Notes + ----- .. plot:: mpl_examples/pylab_examples/vline_hline_demo.py See also -------- - vlines : horizontal lines + vlines : vertical lines """ # We do the conversion first since not all unitized data is uniform @@ -3753,20 +3755,22 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid', Respective beginning and end of each line. If scalars are provided, all lines will have same length. - colors : a line collections color argument, either a single color - or a list of colors + colors : array_like of colors, optional, default: 'k' - linestyles : ['solid' | 'dashed' | 'dashdot' | 'dotted'], optional, - default : 'solid' + linestyles : ['solid' | 'dashed' | 'dashdot' | 'dotted'], optional label : string, optional, default: '' Returns ------- - :class:`~matplotlib.collections.LineCollection` + matplotlib.collections.LineCollection - Example - ------- + Other parameters + ---------------- + kwargs correspond to matplotlib.collections.LineCollection properties. + + Notes + ----- .. plot:: mpl_examples/pylab_examples/vline_hline_demo.py See also From 0de3de8e9f468c029efebf4479ba59332ffe2cb5 Mon Sep 17 00:00:00 2001 From: Nelle Varoquaux Date: Thu, 28 Feb 2013 15:33:13 +0100 Subject: [PATCH 4/4] DOC didn't render properly --- lib/matplotlib/axes.py | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/lib/matplotlib/axes.py b/lib/matplotlib/axes.py index a14fe8681998..f357feb946ce 100644 --- a/lib/matplotlib/axes.py +++ b/lib/matplotlib/axes.py @@ -3660,10 +3660,10 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid', Parameters ---------- - y : scalar or 1D array like + y : scalar or 1D array_like y-indexes where to plot the lines. - xmin, xmax : scalar or 1D array like + xmin, xmax : scalar or 1D array_like Respective beginning and end of each line. If scalars are provided, all lines will have same length. @@ -3675,19 +3675,20 @@ def hlines(self, y, xmin, xmax, colors='k', linestyles='solid', Returns ------- - matplotlib.collections.LineCollection + lines : `~matplotlib.collections.LineCollection` Other parameters ---------------- - kwargs correspond to matplotlib.collections.LineCollection properties. - - Notes - ----- - .. plot:: mpl_examples/pylab_examples/vline_hline_demo.py + kwargs : `~matplotlib.collections.LineCollection` properties. See also -------- vlines : vertical lines + + Examples + -------- + .. plot:: mpl_examples/pylab_examples/vline_hline_demo.py + """ # We do the conversion first since not all unitized data is uniform @@ -3748,10 +3749,10 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid', Parameters ---------- - x : scalar or 1D array like + x : scalar or 1D array_like x-indexes where to plot the lines. - xmin, xmax : scalar or 1D array like + xmin, xmax : scalar or 1D array_like Respective beginning and end of each line. If scalars are provided, all lines will have same length. @@ -3763,20 +3764,20 @@ def vlines(self, x, ymin, ymax, colors='k', linestyles='solid', Returns ------- - matplotlib.collections.LineCollection + lines : `~matplotlib.collections.LineCollection` Other parameters ---------------- - kwargs correspond to matplotlib.collections.LineCollection properties. - - Notes - ----- - .. plot:: mpl_examples/pylab_examples/vline_hline_demo.py + kwargs : `~matplotlib.collections.LineCollection` properties. See also -------- hlines : horizontal lines + Examples + --------- + .. plot:: mpl_examples/pylab_examples/vline_hline_demo.py + """ self._process_unit_info(xdata=x, ydata=[ymin, ymax], kwargs=kwargs)