-
-
Notifications
You must be signed in to change notification settings - Fork 7.9k
Adding headers for examples/units for MEP12/sphinx-gallery compliance #8254
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
their axes parent, so you must init the artists with the axes instance | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would change this 'init' to the full 'initialize'... |
||
if you want to initialize them with unit data, or else they will not | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ... and 'initialize them with unit data' to 'use them with unit data'. |
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If this is too long, I'd break after the positional arguments instead; this doesn't look that great. |
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same here. |
||
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() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
""" | ||
=================== | ||
Bar demo with units | ||
=================== | ||
|
||
plot using a variety of cm vs inches conversions. The example shows | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Also, spell out centimetre (inches is not abbreviated). |
||
how default unit instrospection works (ax1), how various keywords can | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. instrospection -> introspection |
||
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() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,13 @@ | ||
""" | ||
========================= | ||
Group barchart with units | ||
========================= | ||
|
||
This is the same example as | ||
<a href='http://matplotlib.org/examples/api/barchart_demo.html'> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there is probably a better way of linking between examples instead of using a hyperlink, but I can't think of how to at the moment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think this works. Once we'll finish the migration to sphinx gallery, rst markup will work. |
||
the barchart demo</a> 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() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,13 @@ | ||
""" | ||
========== | ||
Evans test | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Who or what is "Evans"? Does anyone know? @tacaswell? I think this needs a different name. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This all predates me. I assume someone from JPL |
||
========== | ||
|
||
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 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,8 @@ | ||
""" | ||
============ | ||
Radian ticks | ||
============ | ||
|
||
Plot with radians from the basic_units mockup example package | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you add a full stop and a newline at the end of the first sentence? |
||
This example shows how the unit class can determine the tick locating, | ||
formatting and axis labeling. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you put a full stop at the end of this sentence?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also capitalize Matplotlib if you change this line.