From ae474c4c26b7e7f3a6c9dfa2e81155ab49fdbb20 Mon Sep 17 00:00:00 2001 From: Tim Hoffmann <2836374+timhoffm@users.noreply.github.com> Date: Mon, 13 Jan 2020 01:05:37 +0100 Subject: [PATCH] Python style cleanup in examples --- examples/animation/random_walk.py | 4 ++-- examples/axisartist/demo_parasite_axes2.py | 4 ++-- examples/axisartist/simple_axisartist1.py | 4 ++-- examples/misc/patheffect_demo.py | 16 ++++++++-------- examples/statistics/barchart_demo.py | 8 ++++---- .../subplots_axes_and_figures/secondary_axis.py | 13 +++++++------ 6 files changed, 25 insertions(+), 24 deletions(-) diff --git a/examples/animation/random_walk.py b/examples/animation/random_walk.py index 1f9e43334d57..07e4707517f2 100644 --- a/examples/animation/random_walk.py +++ b/examples/animation/random_walk.py @@ -36,8 +36,8 @@ def gen_rand_line(length, dims=2): return line_data -def update_lines(num, dataLines, lines): - for line, data in zip(lines, dataLines): +def update_lines(num, data_lines, lines): + for line, data in zip(lines, data_lines): # NOTE: there is no .set_data() for 3 dim data... line.set_data(data[0:2, :num]) line.set_3d_properties(data[2, :num]) diff --git a/examples/axisartist/demo_parasite_axes2.py b/examples/axisartist/demo_parasite_axes2.py index 77bb674c272a..eca4b562bac5 100644 --- a/examples/axisartist/demo_parasite_axes2.py +++ b/examples/axisartist/demo_parasite_axes2.py @@ -23,10 +23,10 @@ the :doc:`/gallery/ticks_and_spines/multiple_yaxis_with_spines` example. """ from mpl_toolkits.axes_grid1 import host_subplot -import mpl_toolkits.axisartist as AA +from mpl_toolkits import axisartist import matplotlib.pyplot as plt -host = host_subplot(111, axes_class=AA.Axes) +host = host_subplot(111, axes_class=axisartist.Axes) plt.subplots_adjust(right=0.75) par1 = host.twinx() diff --git a/examples/axisartist/simple_axisartist1.py b/examples/axisartist/simple_axisartist1.py index ee2b44c5bec2..3c702c347425 100644 --- a/examples/axisartist/simple_axisartist1.py +++ b/examples/axisartist/simple_axisartist1.py @@ -5,11 +5,11 @@ """ import matplotlib.pyplot as plt -import mpl_toolkits.axisartist as AA +from mpl_toolkits import axisartist fig = plt.figure() fig.subplots_adjust(right=0.85) -ax = AA.Subplot(fig, 1, 1, 1) +ax = axisartist.Subplot(fig, 1, 1, 1) fig.add_subplot(ax) # make some axis invisible diff --git a/examples/misc/patheffect_demo.py b/examples/misc/patheffect_demo.py index 4455d63cecf6..618877b1a48e 100644 --- a/examples/misc/patheffect_demo.py +++ b/examples/misc/patheffect_demo.py @@ -5,7 +5,7 @@ """ import matplotlib.pyplot as plt -import matplotlib.patheffects as PathEffects +from matplotlib import patheffects import numpy as np plt.figure(figsize=(8, 3)) @@ -15,13 +15,13 @@ arrowprops=dict(arrowstyle="->", connectionstyle="angle3", lw=2), size=20, ha="center", - path_effects=[PathEffects.withStroke(linewidth=3, + path_effects=[patheffects.withStroke(linewidth=3, foreground="w")]) txt.arrow_patch.set_path_effects([ - PathEffects.Stroke(linewidth=5, foreground="w"), - PathEffects.Normal()]) + patheffects.Stroke(linewidth=5, foreground="w"), + patheffects.Normal()]) -pe = [PathEffects.withStroke(linewidth=3, +pe = [patheffects.withStroke(linewidth=3, foreground="w")] ax1.grid(True, linestyle="-", path_effects=pe) @@ -31,16 +31,16 @@ cntr = ax2.contour(arr, colors="k") plt.setp(cntr.collections, path_effects=[ - PathEffects.withStroke(linewidth=3, foreground="w")]) + patheffects.withStroke(linewidth=3, foreground="w")]) clbls = ax2.clabel(cntr, fmt="%2.0f", use_clabeltext=True) plt.setp(clbls, path_effects=[ - PathEffects.withStroke(linewidth=3, foreground="w")]) + patheffects.withStroke(linewidth=3, foreground="w")]) # shadow as a path effect ax3 = plt.subplot(133) p1, = ax3.plot([0, 1], [0, 1]) leg = ax3.legend([p1], ["Line 1"], fancybox=True, loc='upper left') -leg.legendPatch.set_path_effects([PathEffects.withSimplePatchShadow()]) +leg.legendPatch.set_path_effects([patheffects.withSimplePatchShadow()]) plt.show() diff --git a/examples/statistics/barchart_demo.py b/examples/statistics/barchart_demo.py index df95c3203e3b..e67a7f5320b6 100644 --- a/examples/statistics/barchart_demo.py +++ b/examples/statistics/barchart_demo.py @@ -95,7 +95,7 @@ def plot_student_results(student, scores, cohort_size): # Set the right-hand Y-axis ticks and labels ax2 = ax1.twinx() - scoreLabels = [format_score(scores[k].score, k) for k in test_names] + score_labels = [format_score(scores[k].score, k) for k in test_names] # set the tick locations ax2.set_yticks(pos) @@ -104,7 +104,7 @@ def plot_student_results(student, scores, cohort_size): ax2.set_ylim(ax1.get_ylim()) # set the tick labels - ax2.set_yticklabels(scoreLabels) + ax2.set_yticklabels(score_labels) ax2.set_ylabel('Test Scores') @@ -122,7 +122,7 @@ def plot_student_results(student, scores, cohort_size): # converting width to int type width = int(rect.get_width()) - rankStr = attach_ordinal(width) + rank_str = attach_ordinal(width) # The bars aren't wide enough to print the ranking inside if width < 40: # Shift the text to the right side of the right edge @@ -139,7 +139,7 @@ def plot_student_results(student, scores, cohort_size): # Center the text vertically in the bar yloc = rect.get_y() + rect.get_height() / 2 - label = ax1.annotate(rankStr, xy=(width, yloc), xytext=(xloc, 0), + label = ax1.annotate(rank_str, xy=(width, yloc), xytext=(xloc, 0), textcoords="offset points", ha=align, va='center', color=clr, weight='bold', clip_on=True) diff --git a/examples/subplots_axes_and_figures/secondary_axis.py b/examples/subplots_axes_and_figures/secondary_axis.py index d0b295321f57..9a6a0fb76b7e 100644 --- a/examples/subplots_axes_and_figures/secondary_axis.py +++ b/examples/subplots_axes_and_figures/secondary_axis.py @@ -131,20 +131,21 @@ def yday2date(x): return y -secaxx = ax.secondary_xaxis('top', functions=(date2yday, yday2date)) -secaxx.set_xlabel('yday [2018]') +secax_x = ax.secondary_xaxis('top', functions=(date2yday, yday2date)) +secax_x.set_xlabel('yday [2018]') -def CtoF(x): +def celsius_to_fahrenheit(x): return x * 1.8 + 32 -def FtoC(x): +def fahrenheit_to_celsius(x): return (x - 32) / 1.8 -secaxy = ax.secondary_yaxis('right', functions=(CtoF, FtoC)) -secaxy.set_ylabel(r'$T\ [^oF]$') +secax_y = ax.secondary_yaxis( + 'right', functions=(celsius_to_fahrenheit, fahrenheit_to_celsius)) +secax_y.set_ylabel(r'$T\ [^oF]$') plt.show()