diff --git a/examples/event_handling/pipong.py b/examples/event_handling/pipong.py index 5a080c88752c..b2ff1ab76e70 100644 --- a/examples/event_handling/pipong.py +++ b/examples/event_handling/pipong.py @@ -126,18 +126,18 @@ def __init__(self, ax): self.ax = ax ax.set_ylim([-1, 1]) ax.set_xlim([0, 7]) - padAx = 0 - padBx = .50 - padAy = padBy = .30 - padBx += 6.3 + pad_a_x = 0 + pad_b_x = .50 + pad_a_y = pad_b_y = .30 + pad_b_x += 6.3 # pads - pA, = self.ax.barh(padAy, .2, + pA, = self.ax.barh(pad_a_y, .2, height=.3, color='k', alpha=.5, edgecolor='b', lw=2, label="Player B", animated=True) - pB, = self.ax.barh(padBy, .2, - height=.3, left=padBx, color='k', alpha=.5, + pB, = self.ax.barh(pad_b_y, .2, + height=.3, left=pad_b_x, color='k', alpha=.5, edgecolor='r', lw=2, label="Player A", animated=True) @@ -169,8 +169,8 @@ def __init__(self, ax): self.on = False self.inst = True # show instructions from the beginning self.background = None - self.pads = [Pad(pA, padAx, padAy), - Pad(pB, padBx, padBy, 'r')] + self.pads = [Pad(pA, pad_a_x, pad_a_y), + Pad(pB, pad_b_x, pad_b_y, 'r')] self.pucks = [] self.i = self.ax.annotate(instructions, (.5, 0.5), name='monospace', diff --git a/examples/statistics/boxplot_demo.py b/examples/statistics/boxplot_demo.py index 82aef0535582..6f1866b62124 100644 --- a/examples/statistics/boxplot_demo.py +++ b/examples/statistics/boxplot_demo.py @@ -8,8 +8,8 @@ The following examples show off how to visualize boxplots with Matplotlib. There are many options to control their appearance and the statistics that they use to summarize the data. - """ + import matplotlib.pyplot as plt import numpy as np from matplotlib.patches import Polygon @@ -130,23 +130,23 @@ medians = np.empty(num_boxes) for i in range(num_boxes): box = bp['boxes'][i] - boxX = [] - boxY = [] + box_x = [] + box_y = [] for j in range(5): - boxX.append(box.get_xdata()[j]) - boxY.append(box.get_ydata()[j]) - box_coords = np.column_stack([boxX, boxY]) + box_x.append(box.get_xdata()[j]) + box_y.append(box.get_ydata()[j]) + box_coords = np.column_stack([box_x, box_y]) # Alternate between Dark Khaki and Royal Blue ax1.add_patch(Polygon(box_coords, facecolor=box_colors[i % 2])) # Now draw the median lines back over what we just filled in med = bp['medians'][i] - medianX = [] - medianY = [] + median_x = [] + median_y = [] for j in range(2): - medianX.append(med.get_xdata()[j]) - medianY.append(med.get_ydata()[j]) - ax1.plot(medianX, medianY, 'k') - medians[i] = medianY[0] + median_x.append(med.get_xdata()[j]) + median_y.append(med.get_ydata()[j]) + ax1.plot(median_x, median_y, 'k') + medians[i] = median_y[0] # Finally, overplot the sample averages, with horizontal alignment # in the center of each box ax1.plot(np.average(med.get_xdata()), np.average(data[i]), @@ -193,22 +193,20 @@ # We can then use the boxplot along with this function to show these intervals. -def fakeBootStrapper(n): +def fake_bootstrapper(n): """ This is just a placeholder for the user's method of bootstrapping the median and its confidence intervals. - Returns an arbitrary median and confidence intervals - packed into a tuple + Returns an arbitrary median and confidence interval packed into a tuple. """ if n == 1: med = 0.1 - CI = (-0.25, 0.25) + ci = (-0.25, 0.25) else: med = 0.2 - CI = (-0.35, 0.50) - - return med, CI + ci = (-0.35, 0.50) + return med, ci inc = 0.1 e1 = np.random.normal(0, 1, size=500) @@ -217,10 +215,10 @@ def fakeBootStrapper(n): e4 = np.random.normal(0, 1 + 2*inc, size=500) treatments = [e1, e2, e3, e4] -med1, CI1 = fakeBootStrapper(1) -med2, CI2 = fakeBootStrapper(2) +med1, ci1 = fake_bootstrapper(1) +med2, ci2 = fake_bootstrapper(2) medians = [None, None, med1, med2] -conf_intervals = [None, None, CI1, CI2] +conf_intervals = [None, None, ci1, ci2] fig, ax = plt.subplots() pos = np.array(range(len(treatments))) + 1 diff --git a/examples/statistics/customized_violin.py b/examples/statistics/customized_violin.py index c686b3096776..86c35893e370 100644 --- a/examples/statistics/customized_violin.py +++ b/examples/statistics/customized_violin.py @@ -60,12 +60,12 @@ def set_axis_style(ax, labels): whiskers = np.array([ adjacent_values(sorted_array, q1, q3) for sorted_array, q1, q3 in zip(data, quartile1, quartile3)]) -whiskersMin, whiskersMax = whiskers[:, 0], whiskers[:, 1] +whiskers_min, whiskers_max = whiskers[:, 0], whiskers[:, 1] inds = np.arange(1, len(medians) + 1) ax2.scatter(inds, medians, marker='o', color='white', s=30, zorder=3) ax2.vlines(inds, quartile1, quartile3, color='k', linestyle='-', lw=5) -ax2.vlines(inds, whiskersMin, whiskersMax, color='k', linestyle='-', lw=1) +ax2.vlines(inds, whiskers_min, whiskers_max, color='k', linestyle='-', lw=1) # set style for the axes labels = ['A', 'B', 'C', 'D'] diff --git a/examples/units/basic_units.py b/examples/units/basic_units.py index dc96d71f385b..cec4657bfa75 100644 --- a/examples/units/basic_units.py +++ b/examples/units/basic_units.py @@ -122,12 +122,8 @@ def __new__(cls, value, unit): try: subcls = type(f'TaggedValue_of_{value_class.__name__}', (cls, value_class), {}) - if subcls not in units.registry: - units.registry[subcls] = basicConverter return object.__new__(subcls) except TypeError: - if cls not in units.registry: - units.registry[cls] = basicConverter return object.__new__(cls) def __init__(self, value, unit): @@ -378,6 +374,4 @@ def cos(x): return math.cos(x.convert_to(radians).get_value()) -basicConverter = BasicUnitConverter() -units.registry[BasicUnit] = basicConverter -units.registry[TaggedValue] = basicConverter +units.registry[BasicUnit] = units.registry[TaggedValue] = BasicUnitConverter()