From 39d9800e6128ddd914ddb8f42f187538dbb49fbd Mon Sep 17 00:00:00 2001 From: yinleon Date: Thu, 9 Mar 2017 20:05:23 -0800 Subject: [PATCH] added headers for sphinx compliance --- examples/units/annotate_with_units.py | 9 +++++++++ examples/units/artist_tests.py | 14 ++++++++++---- examples/units/bar_demo2.py | 6 +++++- examples/units/bar_unit_demo.py | 14 ++++++++++++-- examples/units/evans_test.py | 10 ++++++++-- examples/units/radian_demo.py | 4 ++++ examples/units/units_sample.py | 15 ++++++++------- examples/units/units_scatter.py | 4 +++- 8 files changed, 59 insertions(+), 17 deletions(-) diff --git a/examples/units/annotate_with_units.py b/examples/units/annotate_with_units.py index b322e2dd2c89..67fea4584e2f 100644 --- a/examples/units/annotate_with_units.py +++ b/examples/units/annotate_with_units.py @@ -1,3 +1,12 @@ +""" +===================== +Annotation with units +===================== + +The example illustrates how to create text and arrow +annotations using a centimeter-scale plot. + +""" import matplotlib.pyplot as plt from basic_units import cm diff --git a/examples/units/artist_tests.py b/examples/units/artist_tests.py index 122d1a6b00d4..0586efebbd32 100644 --- a/examples/units/artist_tests.py +++ b/examples/units/artist_tests.py @@ -1,10 +1,14 @@ """ +============ +Artist tests +============ + Test unit support with each of the matplotlib primitive artist types The axes handles unit conversions and the artists keep a pointer to their axes parent, so you must init the artists with the axes instance if you want to initialize them with unit data, or else they will not -know how to convert the units to scalars +know how to convert the units to scalars. """ import random import matplotlib.lines as lines @@ -34,13 +38,15 @@ ax.add_collection(lc) # test a plain-ol-line -line = lines.Line2D([0*cm, 1.5*cm], [0*cm, 2.5*cm], lw=2, color='black', axes=ax) +line = lines.Line2D( + [0*cm, 1.5*cm], [0*cm, 2.5*cm], lw=2, color='black', axes=ax) ax.add_line(line) if 0: # test a patch # Not supported at present. - rect = patches.Rectangle((1*cm, 1*cm), width=5*cm, height=2*cm, alpha=0.2, axes=ax) + rect = patches.Rectangle( + (1*cm, 1*cm), width=5*cm, height=2*cm, alpha=0.2, axes=ax) ax.add_patch(rect) @@ -49,7 +55,7 @@ ax.set_xlim(-1*cm, 10*cm) ax.set_ylim(-1*cm, 10*cm) -#ax.xaxis.set_units(inch) +# ax.xaxis.set_units(inch) ax.grid(True) ax.set_title("Artists with units") plt.show() diff --git a/examples/units/bar_demo2.py b/examples/units/bar_demo2.py index e7fb8bdde07c..325915e92a10 100644 --- a/examples/units/bar_demo2.py +++ b/examples/units/bar_demo2.py @@ -1,4 +1,8 @@ """ +=================== +Bar demo with units +=================== + plot using a variety of cm vs inches conversions. The example shows how default unit instrospection works (ax1), how various keywords can be used to set the x and y units to override the defaults (ax2, ax3, @@ -30,7 +34,7 @@ ax4 = fig.add_subplot(2, 2, 4) ax4.bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=inch) -#fig.savefig('simple_conversion_plot.png') +# fig.savefig('simple_conversion_plot.png') ax4.set_xlim(2*cm, 6*cm) # cm are converted to inches plt.show() diff --git a/examples/units/bar_unit_demo.py b/examples/units/bar_unit_demo.py index e544a63d7629..1e275cbd2c79 100644 --- a/examples/units/bar_unit_demo.py +++ b/examples/units/bar_unit_demo.py @@ -1,3 +1,13 @@ +""" +========================= +Group barchart with units +========================= + +This is the same example as + +the barchart demo in centimeters. +""" + import numpy as np from basic_units import cm, inch import matplotlib.pyplot as plt @@ -16,7 +26,8 @@ womenMeans = (145*cm, 149*cm, 172*cm, 165*cm, 200*cm) womenStd = (30*cm, 25*cm, 20*cm, 31*cm, 22*cm) -p2 = ax.bar(ind + width, womenMeans, width, color='y', bottom=0*cm, yerr=womenStd) +p2 = ax.bar(ind + width, womenMeans, width, + color='y', bottom=0*cm, yerr=womenStd) ax.set_title('Scores by group and gender') ax.set_xticks(ind + width / 2) @@ -26,5 +37,4 @@ ax.yaxis.set_units(inch) ax.autoscale_view() -#plt.savefig('barchart_demo') plt.show() diff --git a/examples/units/evans_test.py b/examples/units/evans_test.py index 8f2686c33e4a..85b6dbef1c78 100644 --- a/examples/units/evans_test.py +++ b/examples/units/evans_test.py @@ -1,8 +1,13 @@ """ +========== +Evans test +========== + A mockup "Foo" units class which supports conversion and different tick formatting depending on the "unit". -Here the "unit" is just a scalar conversion factor, but this example shows mpl is -entirely agnostic to what kind of units client packages use +Here the "unit" is just a scalar conversion factor, but this example shows mpl +is entirely agnostic to what kind of units client packages use. + """ from matplotlib.cbook import iterable import matplotlib.units as units @@ -58,6 +63,7 @@ def default_units(x, axis): else: return x.unit + units.registry[Foo] = FooConverter() # create some Foos diff --git a/examples/units/radian_demo.py b/examples/units/radian_demo.py index 3eeca931e75d..e2e301169d60 100644 --- a/examples/units/radian_demo.py +++ b/examples/units/radian_demo.py @@ -1,4 +1,8 @@ """ +============ +Radian ticks +============ + Plot with radians from the basic_units mockup example package This example shows how the unit class can determine the tick locating, formatting and axis labeling. diff --git a/examples/units/units_sample.py b/examples/units/units_sample.py index 95be1bbef3e6..3057dbe05a0d 100644 --- a/examples/units/units_sample.py +++ b/examples/units/units_sample.py @@ -1,10 +1,12 @@ """ -plot using a variety of cm vs inches conversions. The example shows -how default unit introspection works (ax1), how various keywords can -be used to set the x and y units to override the defaults (ax2, ax3, -ax4) and how one can set the xlimits using scalars (ax3, current units -assumed) or units (conversions applied to get the numbers to current -units) +====================== +Inches and Centimeters +====================== + +The example illustrates the ability to override default x and y units (ax1) to +inches and centimeters using the `xunits` and `yunits` parameters for the +`plot` function. Note that conversions are applied to get numbers to correct +units. """ from basic_units import cm, inch @@ -27,7 +29,6 @@ ax4 = fig.add_subplot(2, 2, 4) ax4.plot(cms, cms, xunits=inch, yunits=inch) -#fig.savefig('simple_conversion_plot.png') ax4.set_xlim(3*cm, 6*cm) # cm are converted to inches plt.show() diff --git a/examples/units/units_scatter.py b/examples/units/units_scatter.py index 8a8e43e6ca8e..4723369943cf 100644 --- a/examples/units/units_scatter.py +++ b/examples/units/units_scatter.py @@ -1,5 +1,7 @@ """ -Demonstrate unit handling +============= +Unit handling +============= basic_units is a mockup of a true units package used for testing purposed, which illustrates the basic interface that a units package