Skip to content

Commit ae474c4

Browse files
committed
Python style cleanup in examples
1 parent 2c5c351 commit ae474c4

File tree

6 files changed

+25
-24
lines changed

6 files changed

+25
-24
lines changed

examples/animation/random_walk.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ def gen_rand_line(length, dims=2):
3636
return line_data
3737

3838

39-
def update_lines(num, dataLines, lines):
40-
for line, data in zip(lines, dataLines):
39+
def update_lines(num, data_lines, lines):
40+
for line, data in zip(lines, data_lines):
4141
# NOTE: there is no .set_data() for 3 dim data...
4242
line.set_data(data[0:2, :num])
4343
line.set_3d_properties(data[2, :num])

examples/axisartist/demo_parasite_axes2.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
the :doc:`/gallery/ticks_and_spines/multiple_yaxis_with_spines` example.
2424
"""
2525
from mpl_toolkits.axes_grid1 import host_subplot
26-
import mpl_toolkits.axisartist as AA
26+
from mpl_toolkits import axisartist
2727
import matplotlib.pyplot as plt
2828

29-
host = host_subplot(111, axes_class=AA.Axes)
29+
host = host_subplot(111, axes_class=axisartist.Axes)
3030
plt.subplots_adjust(right=0.75)
3131

3232
par1 = host.twinx()

examples/axisartist/simple_axisartist1.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
66
"""
77
import matplotlib.pyplot as plt
8-
import mpl_toolkits.axisartist as AA
8+
from mpl_toolkits import axisartist
99

1010
fig = plt.figure()
1111
fig.subplots_adjust(right=0.85)
12-
ax = AA.Subplot(fig, 1, 1, 1)
12+
ax = axisartist.Subplot(fig, 1, 1, 1)
1313
fig.add_subplot(ax)
1414

1515
# make some axis invisible

examples/misc/patheffect_demo.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
66
"""
77
import matplotlib.pyplot as plt
8-
import matplotlib.patheffects as PathEffects
8+
from matplotlib import patheffects
99
import numpy as np
1010

1111
plt.figure(figsize=(8, 3))
@@ -15,13 +15,13 @@
1515
arrowprops=dict(arrowstyle="->",
1616
connectionstyle="angle3", lw=2),
1717
size=20, ha="center",
18-
path_effects=[PathEffects.withStroke(linewidth=3,
18+
path_effects=[patheffects.withStroke(linewidth=3,
1919
foreground="w")])
2020
txt.arrow_patch.set_path_effects([
21-
PathEffects.Stroke(linewidth=5, foreground="w"),
22-
PathEffects.Normal()])
21+
patheffects.Stroke(linewidth=5, foreground="w"),
22+
patheffects.Normal()])
2323

24-
pe = [PathEffects.withStroke(linewidth=3,
24+
pe = [patheffects.withStroke(linewidth=3,
2525
foreground="w")]
2626
ax1.grid(True, linestyle="-", path_effects=pe)
2727

@@ -31,16 +31,16 @@
3131
cntr = ax2.contour(arr, colors="k")
3232

3333
plt.setp(cntr.collections, path_effects=[
34-
PathEffects.withStroke(linewidth=3, foreground="w")])
34+
patheffects.withStroke(linewidth=3, foreground="w")])
3535

3636
clbls = ax2.clabel(cntr, fmt="%2.0f", use_clabeltext=True)
3737
plt.setp(clbls, path_effects=[
38-
PathEffects.withStroke(linewidth=3, foreground="w")])
38+
patheffects.withStroke(linewidth=3, foreground="w")])
3939

4040
# shadow as a path effect
4141
ax3 = plt.subplot(133)
4242
p1, = ax3.plot([0, 1], [0, 1])
4343
leg = ax3.legend([p1], ["Line 1"], fancybox=True, loc='upper left')
44-
leg.legendPatch.set_path_effects([PathEffects.withSimplePatchShadow()])
44+
leg.legendPatch.set_path_effects([patheffects.withSimplePatchShadow()])
4545

4646
plt.show()

examples/statistics/barchart_demo.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def plot_student_results(student, scores, cohort_size):
9595
# Set the right-hand Y-axis ticks and labels
9696
ax2 = ax1.twinx()
9797

98-
scoreLabels = [format_score(scores[k].score, k) for k in test_names]
98+
score_labels = [format_score(scores[k].score, k) for k in test_names]
9999

100100
# set the tick locations
101101
ax2.set_yticks(pos)
@@ -104,7 +104,7 @@ def plot_student_results(student, scores, cohort_size):
104104
ax2.set_ylim(ax1.get_ylim())
105105

106106
# set the tick labels
107-
ax2.set_yticklabels(scoreLabels)
107+
ax2.set_yticklabels(score_labels)
108108

109109
ax2.set_ylabel('Test Scores')
110110

@@ -122,7 +122,7 @@ def plot_student_results(student, scores, cohort_size):
122122
# converting width to int type
123123
width = int(rect.get_width())
124124

125-
rankStr = attach_ordinal(width)
125+
rank_str = attach_ordinal(width)
126126
# The bars aren't wide enough to print the ranking inside
127127
if width < 40:
128128
# Shift the text to the right side of the right edge
@@ -139,7 +139,7 @@ def plot_student_results(student, scores, cohort_size):
139139

140140
# Center the text vertically in the bar
141141
yloc = rect.get_y() + rect.get_height() / 2
142-
label = ax1.annotate(rankStr, xy=(width, yloc), xytext=(xloc, 0),
142+
label = ax1.annotate(rank_str, xy=(width, yloc), xytext=(xloc, 0),
143143
textcoords="offset points",
144144
ha=align, va='center',
145145
color=clr, weight='bold', clip_on=True)

examples/subplots_axes_and_figures/secondary_axis.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -131,20 +131,21 @@ def yday2date(x):
131131
return y
132132

133133

134-
secaxx = ax.secondary_xaxis('top', functions=(date2yday, yday2date))
135-
secaxx.set_xlabel('yday [2018]')
134+
secax_x = ax.secondary_xaxis('top', functions=(date2yday, yday2date))
135+
secax_x.set_xlabel('yday [2018]')
136136

137137

138-
def CtoF(x):
138+
def celsius_to_fahrenheit(x):
139139
return x * 1.8 + 32
140140

141141

142-
def FtoC(x):
142+
def fahrenheit_to_celsius(x):
143143
return (x - 32) / 1.8
144144

145145

146-
secaxy = ax.secondary_yaxis('right', functions=(CtoF, FtoC))
147-
secaxy.set_ylabel(r'$T\ [^oF]$')
146+
secax_y = ax.secondary_yaxis(
147+
'right', functions=(celsius_to_fahrenheit, fahrenheit_to_celsius))
148+
secax_y.set_ylabel(r'$T\ [^oF]$')
148149

149150
plt.show()
150151

0 commit comments

Comments
 (0)