Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5cbc072

Browse files
abhinuvpitaleQuLogic
authored andcommitted
Fix docs : remove "if 1:" blocks in examples
* change proposed in issue #12191 removed the confusing if 1: as propsed in #12191 * change requested in #12191 * added main() to resolve comments from #12191 * update #12191 * flake-8 corrections #12191 * update ```plt.show``` for #12191 * flake8 update #12191 * Update demo_annotation_box.py * Update demo_agg_filter.py * Update patheffect_demo.py * Update demo_text_rotation_mode.py * Update demo_text_path.py * Update demo_curvelinear_grid.py * Update demo_curvelinear_grid2.py * flake8 compliant * flake8 compliant * flake8 compliant * Update patheffect_demo.py * Update demo_annotation_box.py * flake8 compliant * Update demo_text_rotation_mode.py * Update patheffect_demo.py * Update demo_annotation_box.py
1 parent 5229d4a commit 5cbc072

File tree

7 files changed

+123
-125
lines changed

7 files changed

+123
-125
lines changed

examples/axisartist/demo_curvelinear_grid.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ def curvelinear_test2(fig):
131131
ax1.grid(True, zorder=0)
132132

133133

134-
if 1:
134+
if __name__ == "__main__":
135135
fig = plt.figure(figsize=(7, 4))
136136

137137
curvelinear_test1(fig)

examples/axisartist/demo_curvelinear_grid2.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def inv_tr(x, y):
6464
grid_helper.grid_finder.grid_locator2._nbins = 6
6565

6666

67-
if 1:
67+
if __name__ == "__main__":
6868
fig = plt.figure(figsize=(7, 4))
6969
curvelinear_test1(fig)
7070
plt.show()

examples/misc/demo_agg_filter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@ def light_filter_pie(ax):
307307
shadow.set_zorder(pies[0][0].get_zorder() - 0.1)
308308

309309

310-
if 1:
310+
if __name__ == "__main__":
311311

312312
plt.figure(figsize=(6, 6))
313313
plt.subplots_adjust(left=0.05, right=0.95)

examples/misc/patheffect_demo.py

Lines changed: 36 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -8,40 +8,39 @@
88
import matplotlib.patheffects as PathEffects
99
import numpy as np
1010

11-
if 1:
12-
plt.figure(figsize=(8, 3))
13-
ax1 = plt.subplot(131)
14-
ax1.imshow([[1, 2], [2, 3]])
15-
txt = ax1.annotate("test", (1., 1.), (0., 0),
16-
arrowprops=dict(arrowstyle="->",
17-
connectionstyle="angle3", lw=2),
18-
size=20, ha="center",
19-
path_effects=[PathEffects.withStroke(linewidth=3,
20-
foreground="w")])
21-
txt.arrow_patch.set_path_effects([
22-
PathEffects.Stroke(linewidth=5, foreground="w"),
23-
PathEffects.Normal()])
24-
25-
pe = [PathEffects.withStroke(linewidth=3,
26-
foreground="w")]
27-
ax1.grid(True, linestyle="-", path_effects=pe)
28-
29-
ax2 = plt.subplot(132)
30-
arr = np.arange(25).reshape((5, 5))
31-
ax2.imshow(arr)
32-
cntr = ax2.contour(arr, colors="k")
33-
34-
plt.setp(cntr.collections, path_effects=[
35-
PathEffects.withStroke(linewidth=3, foreground="w")])
36-
37-
clbls = ax2.clabel(cntr, fmt="%2.0f", use_clabeltext=True)
38-
plt.setp(clbls, path_effects=[
39-
PathEffects.withStroke(linewidth=3, foreground="w")])
40-
41-
# shadow as a path effect
42-
ax3 = plt.subplot(133)
43-
p1, = ax3.plot([0, 1], [0, 1])
44-
leg = ax3.legend([p1], ["Line 1"], fancybox=True, loc='upper left')
45-
leg.legendPatch.set_path_effects([PathEffects.withSimplePatchShadow()])
46-
47-
plt.show()
11+
plt.figure(figsize=(8, 3))
12+
ax1 = plt.subplot(131)
13+
ax1.imshow([[1, 2], [2, 3]])
14+
txt = ax1.annotate("test", (1., 1.), (0., 0),
15+
arrowprops=dict(arrowstyle="->",
16+
connectionstyle="angle3", lw=2),
17+
size=20, ha="center",
18+
path_effects=[PathEffects.withStroke(linewidth=3,
19+
foreground="w")])
20+
txt.arrow_patch.set_path_effects([
21+
PathEffects.Stroke(linewidth=5, foreground="w"),
22+
PathEffects.Normal()])
23+
24+
pe = [PathEffects.withStroke(linewidth=3,
25+
foreground="w")]
26+
ax1.grid(True, linestyle="-", path_effects=pe)
27+
28+
ax2 = plt.subplot(132)
29+
arr = np.arange(25).reshape((5, 5))
30+
ax2.imshow(arr)
31+
cntr = ax2.contour(arr, colors="k")
32+
33+
plt.setp(cntr.collections, path_effects=[
34+
PathEffects.withStroke(linewidth=3, foreground="w")])
35+
36+
clbls = ax2.clabel(cntr, fmt="%2.0f", use_clabeltext=True)
37+
plt.setp(clbls, path_effects=[
38+
PathEffects.withStroke(linewidth=3, foreground="w")])
39+
40+
# shadow as a path effect
41+
ax3 = plt.subplot(133)
42+
p1, = ax3.plot([0, 1], [0, 1])
43+
leg = ax3.legend([p1], ["Line 1"], fancybox=True, loc='upper left')
44+
leg.legendPatch.set_path_effects([PathEffects.withSimplePatchShadow()])
45+
46+
plt.show()

examples/text_labels_and_annotations/demo_annotation_box.py

Lines changed: 82 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -13,86 +13,85 @@
1313
from matplotlib.cbook import get_sample_data
1414

1515

16-
if 1:
17-
fig, ax = plt.subplots()
18-
19-
# Define a 1st position to annotate (display it with a marker)
20-
xy = (0.5, 0.7)
21-
ax.plot(xy[0], xy[1], ".r")
22-
23-
# Annotate the 1st position with a text box ('Test 1')
24-
offsetbox = TextArea("Test 1", minimumdescent=False)
25-
26-
ab = AnnotationBbox(offsetbox, xy,
27-
xybox=(-20, 40),
28-
xycoords='data',
29-
boxcoords="offset points",
30-
arrowprops=dict(arrowstyle="->"))
31-
ax.add_artist(ab)
32-
33-
# Annotate the 1st position with another text box ('Test')
34-
offsetbox = TextArea("Test", minimumdescent=False)
35-
36-
ab = AnnotationBbox(offsetbox, xy,
37-
xybox=(1.02, xy[1]),
38-
xycoords='data',
39-
boxcoords=("axes fraction", "data"),
40-
box_alignment=(0., 0.5),
41-
arrowprops=dict(arrowstyle="->"))
42-
ax.add_artist(ab)
43-
44-
# Define a 2nd position to annotate (don't display with a marker this time)
45-
xy = [0.3, 0.55]
46-
47-
# Annotate the 2nd position with a circle patch
48-
da = DrawingArea(20, 20, 0, 0)
49-
p = Circle((10, 10), 10)
50-
da.add_artist(p)
51-
52-
ab = AnnotationBbox(da, xy,
53-
xybox=(1.02, xy[1]),
54-
xycoords='data',
55-
boxcoords=("axes fraction", "data"),
56-
box_alignment=(0., 0.5),
57-
arrowprops=dict(arrowstyle="->"))
58-
59-
ax.add_artist(ab)
60-
61-
# Annotate the 2nd position with an image (a generated array of pixels)
62-
arr = np.arange(100).reshape((10, 10))
63-
im = OffsetImage(arr, zoom=2)
64-
im.image.axes = ax
65-
66-
ab = AnnotationBbox(im, xy,
67-
xybox=(-50., 50.),
68-
xycoords='data',
69-
boxcoords="offset points",
70-
pad=0.3,
71-
arrowprops=dict(arrowstyle="->"))
72-
73-
ax.add_artist(ab)
74-
75-
# Annotate the 2nd position with another image (a Grace Hopper portrait)
76-
fn = get_sample_data("grace_hopper.png", asfileobj=False)
77-
arr_img = plt.imread(fn, format='png')
78-
79-
imagebox = OffsetImage(arr_img, zoom=0.2)
80-
imagebox.image.axes = ax
81-
82-
ab = AnnotationBbox(imagebox, xy,
83-
xybox=(120., -80.),
84-
xycoords='data',
85-
boxcoords="offset points",
86-
pad=0.5,
87-
arrowprops=dict(
88-
arrowstyle="->",
89-
connectionstyle="angle,angleA=0,angleB=90,rad=3")
90-
)
91-
92-
ax.add_artist(ab)
93-
94-
# Fix the display limits to see everything
95-
ax.set_xlim(0, 1)
96-
ax.set_ylim(0, 1)
97-
98-
plt.show()
16+
fig, ax = plt.subplots()
17+
18+
# Define a 1st position to annotate (display it with a marker)
19+
xy = (0.5, 0.7)
20+
ax.plot(xy[0], xy[1], ".r")
21+
22+
# Annotate the 1st position with a text box ('Test 1')
23+
offsetbox = TextArea("Test 1", minimumdescent=False)
24+
25+
ab = AnnotationBbox(offsetbox, xy,
26+
xybox=(-20, 40),
27+
xycoords='data',
28+
boxcoords="offset points",
29+
arrowprops=dict(arrowstyle="->"))
30+
ax.add_artist(ab)
31+
32+
# Annotate the 1st position with another text box ('Test')
33+
offsetbox = TextArea("Test", minimumdescent=False)
34+
35+
ab = AnnotationBbox(offsetbox, xy,
36+
xybox=(1.02, xy[1]),
37+
xycoords='data',
38+
boxcoords=("axes fraction", "data"),
39+
box_alignment=(0., 0.5),
40+
arrowprops=dict(arrowstyle="->"))
41+
ax.add_artist(ab)
42+
43+
# Define a 2nd position to annotate (don't display with a marker this time)
44+
xy = [0.3, 0.55]
45+
46+
# Annotate the 2nd position with a circle patch
47+
da = DrawingArea(20, 20, 0, 0)
48+
p = Circle((10, 10), 10)
49+
da.add_artist(p)
50+
51+
ab = AnnotationBbox(da, xy,
52+
xybox=(1.02, xy[1]),
53+
xycoords='data',
54+
boxcoords=("axes fraction", "data"),
55+
box_alignment=(0., 0.5),
56+
arrowprops=dict(arrowstyle="->"))
57+
58+
ax.add_artist(ab)
59+
60+
# Annotate the 2nd position with an image (a generated array of pixels)
61+
arr = np.arange(100).reshape((10, 10))
62+
im = OffsetImage(arr, zoom=2)
63+
im.image.axes = ax
64+
65+
ab = AnnotationBbox(im, xy,
66+
xybox=(-50., 50.),
67+
xycoords='data',
68+
boxcoords="offset points",
69+
pad=0.3,
70+
arrowprops=dict(arrowstyle="->"))
71+
72+
ax.add_artist(ab)
73+
74+
# Annotate the 2nd position with another image (a Grace Hopper portrait)
75+
fn = get_sample_data("grace_hopper.png", asfileobj=False)
76+
arr_img = plt.imread(fn, format='png')
77+
78+
imagebox = OffsetImage(arr_img, zoom=0.2)
79+
imagebox.image.axes = ax
80+
81+
ab = AnnotationBbox(imagebox, xy,
82+
xybox=(120., -80.),
83+
xycoords='data',
84+
boxcoords="offset points",
85+
pad=0.5,
86+
arrowprops=dict(
87+
arrowstyle="->",
88+
connectionstyle="angle,angleA=0,angleB=90,rad=3")
89+
)
90+
91+
ax.add_artist(ab)
92+
93+
# Fix the display limits to see everything
94+
ax.set_xlim(0, 1)
95+
ax.set_ylim(0, 1)
96+
97+
plt.show()

examples/text_labels_and_annotations/demo_text_path.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def draw(self, renderer=None):
5656
mpatches.PathPatch.draw(self, renderer)
5757

5858

59-
if 1:
59+
if __name__ == "__main__":
6060

6161
usetex = plt.rcParams["text.usetex"]
6262

examples/text_labels_and_annotations/demo_text_rotation_mode.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def test_rotation_mode(fig, mode, subplot_location):
4242
i += 1
4343

4444

45-
if 1:
45+
if __name__ == "__main__":
4646
import matplotlib.pyplot as plt
4747
fig = plt.figure(figsize=(5.5, 4))
4848
test_rotation_mode(fig, "default", 121)

0 commit comments

Comments
 (0)