Skip to content

Commit 932d469

Browse files
committed
Merge pull request #8254 from yinleon/units
Adding headers for examples/units for MEP12/sphinx-gallery compliance
1 parent 40fa9d3 commit 932d469

8 files changed

+59
-17
lines changed

examples/units/annotate_with_units.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
"""
2+
=====================
3+
Annotation with units
4+
=====================
5+
6+
The example illustrates how to create text and arrow
7+
annotations using a centimeter-scale plot.
8+
9+
"""
110
import matplotlib.pyplot as plt
211
from basic_units import cm
312

examples/units/artist_tests.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
11
"""
2+
============
3+
Artist tests
4+
============
5+
26
Test unit support with each of the matplotlib primitive artist types
37
48
The axes handles unit conversions and the artists keep a pointer to
59
their axes parent, so you must init the artists with the axes instance
610
if you want to initialize them with unit data, or else they will not
7-
know how to convert the units to scalars
11+
know how to convert the units to scalars.
812
"""
913
import random
1014
import matplotlib.lines as lines
@@ -31,13 +35,15 @@
3135
ax.add_collection(lc)
3236

3337
# test a plain-ol-line
34-
line = lines.Line2D([0*cm, 1.5*cm], [0*cm, 2.5*cm], lw=2, color='black', axes=ax)
38+
line = lines.Line2D(
39+
[0*cm, 1.5*cm], [0*cm, 2.5*cm], lw=2, color='black', axes=ax)
3540
ax.add_line(line)
3641

3742
if 0:
3843
# test a patch
3944
# Not supported at present.
40-
rect = patches.Rectangle((1*cm, 1*cm), width=5*cm, height=2*cm, alpha=0.2, axes=ax)
45+
rect = patches.Rectangle(
46+
(1*cm, 1*cm), width=5*cm, height=2*cm, alpha=0.2, axes=ax)
4147
ax.add_patch(rect)
4248

4349

@@ -46,7 +52,7 @@
4652

4753
ax.set_xlim(-1*cm, 10*cm)
4854
ax.set_ylim(-1*cm, 10*cm)
49-
#ax.xaxis.set_units(inch)
55+
# ax.xaxis.set_units(inch)
5056
ax.grid(True)
5157
ax.set_title("Artists with units")
5258
plt.show()

examples/units/bar_demo2.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
===================
3+
Bar demo with units
4+
===================
5+
26
plot using a variety of cm vs inches conversions. The example shows
37
how default unit instrospection works (ax1), how various keywords can
48
be used to set the x and y units to override the defaults (ax2, ax3,
@@ -30,7 +34,7 @@
3034

3135
ax4 = fig.add_subplot(2, 2, 4)
3236
ax4.bar(cms, cms, bottom=bottom, width=width, xunits=inch, yunits=inch)
33-
#fig.savefig('simple_conversion_plot.png')
37+
# fig.savefig('simple_conversion_plot.png')
3438
ax4.set_xlim(2*cm, 6*cm) # cm are converted to inches
3539

3640
plt.show()

examples/units/bar_unit_demo.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,13 @@
1+
"""
2+
=========================
3+
Group barchart with units
4+
=========================
5+
6+
This is the same example as
7+
<a href='http://matplotlib.org/examples/api/barchart_demo.html'>
8+
the barchart demo</a> in centimeters.
9+
"""
10+
111
import numpy as np
212
from basic_units import cm, inch
313
import matplotlib.pyplot as plt
@@ -16,7 +26,8 @@
1626

1727
womenMeans = (145*cm, 149*cm, 172*cm, 165*cm, 200*cm)
1828
womenStd = (30*cm, 25*cm, 20*cm, 31*cm, 22*cm)
19-
p2 = ax.bar(ind + width, womenMeans, width, color='y', bottom=0*cm, yerr=womenStd)
29+
p2 = ax.bar(ind + width, womenMeans, width,
30+
color='y', bottom=0*cm, yerr=womenStd)
2031

2132
ax.set_title('Scores by group and gender')
2233
ax.set_xticks(ind + width / 2)
@@ -26,5 +37,4 @@
2637
ax.yaxis.set_units(inch)
2738
ax.autoscale_view()
2839

29-
#plt.savefig('barchart_demo')
3040
plt.show()

examples/units/evans_test.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,13 @@
11
"""
2+
==========
3+
Evans test
4+
==========
5+
26
A mockup "Foo" units class which supports
37
conversion and different tick formatting depending on the "unit".
4-
Here the "unit" is just a scalar conversion factor, but this example shows mpl is
5-
entirely agnostic to what kind of units client packages use
8+
Here the "unit" is just a scalar conversion factor, but this example shows mpl
9+
is entirely agnostic to what kind of units client packages use.
10+
611
"""
712
from matplotlib.cbook import iterable
813
import matplotlib.units as units
@@ -58,6 +63,7 @@ def default_units(x, axis):
5863
else:
5964
return x.unit
6065

66+
6167
units.registry[Foo] = FooConverter()
6268

6369
# create some Foos

examples/units/radian_demo.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
11
"""
2+
============
3+
Radian ticks
4+
============
5+
26
Plot with radians from the basic_units mockup example package
37
This example shows how the unit class can determine the tick locating,
48
formatting and axis labeling.

examples/units/units_sample.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
"""
2-
plot using a variety of cm vs inches conversions. The example shows
3-
how default unit introspection works (ax1), how various keywords can
4-
be used to set the x and y units to override the defaults (ax2, ax3,
5-
ax4) and how one can set the xlimits using scalars (ax3, current units
6-
assumed) or units (conversions applied to get the numbers to current
7-
units)
2+
======================
3+
Inches and Centimeters
4+
======================
5+
6+
The example illustrates the ability to override default x and y units (ax1) to
7+
inches and centimeters using the `xunits` and `yunits` parameters for the
8+
`plot` function. Note that conversions are applied to get numbers to correct
9+
units.
810
911
"""
1012
from basic_units import cm, inch
@@ -27,7 +29,6 @@
2729

2830
ax4 = fig.add_subplot(2, 2, 4)
2931
ax4.plot(cms, cms, xunits=inch, yunits=inch)
30-
#fig.savefig('simple_conversion_plot.png')
3132
ax4.set_xlim(3*cm, 6*cm) # cm are converted to inches
3233

3334
plt.show()

examples/units/units_scatter.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
"""
2-
Demonstrate unit handling
2+
=============
3+
Unit handling
4+
=============
35
46
basic_units is a mockup of a true units package used for testing
57
purposed, which illustrates the basic interface that a units package

0 commit comments

Comments
 (0)