Skip to content

Commit 028fab4

Browse files
committed
cleaning and formatting
1 parent 389e478 commit 028fab4

15 files changed

+183
-215
lines changed

examples/blitting.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import matplotlib
22
import matplotlib.pyplot as plt
33

4-
matplotlib.use('pygame')
4+
matplotlib.use("pygame")
55
import numpy as np
66

77
x = np.linspace(0, 2 * np.pi, 100)
@@ -45,4 +45,4 @@
4545
# flush any pending GUI events, re-painting the screen if needed
4646
fig.canvas.flush_events()
4747
# you can put a pause in if you want to slow things down
48-
plt.pause(.01)
48+
plt.pause(0.01)

examples/blitting_class.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
import matplotlib.pyplot as plt
22
import numpy as np
33
import matplotlib
4-
matplotlib.use('pygame')
4+
5+
matplotlib.use("pygame")
6+
57

68
class BlitManager:
79
def __init__(self, canvas, animated_artists=()):
@@ -75,6 +77,7 @@ def update(self):
7577
# let the GUI event loop process anything it has to do
7678
cv.flush_events()
7779

80+
7881
x = np.linspace(0, 2 * np.pi, 100)
7982
# make a new figure
8083
fig, ax = plt.subplots()
@@ -102,4 +105,4 @@ def update(self):
102105
fr_number.set_text("frame: {j}".format(j=j))
103106
# tell the blitting manager to do its thing
104107
bm.update()
105-
# plt.pause(1)
108+
# plt.pause(1)

examples/gui_window.py

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
"""Simple script to test from https://pygame-gui.readthedocs.io/en/latest/quick_start.html"""
22

3-
43
import pygame
54
import pygame_gui
65

@@ -11,39 +10,37 @@
1110

1211
pygame.init()
1312

14-
pygame.display.set_caption('Test')
13+
pygame.display.set_caption("Test")
1514
window_surface = pygame.display.set_mode((800, 600))
1615

1716
background = pygame.Surface((800, 600))
18-
background.fill(pygame.Color('#000000'))
17+
background.fill(pygame.Color("#000000"))
1918

2019
manager = pygame_gui.UIManager((800, 600))
2120

22-
fig, axes = plt.subplots(1, 1,)
23-
axes.plot([1,2], [1,2], color='green', label='test')
21+
fig, axes = plt.subplots(1, 1)
22+
axes.plot([1, 2], [1, 2], color="green", label="test")
2423
fig.canvas.draw()
2524

2625

27-
fig2, axes2 = plt.subplots(1, 1,)
28-
axes2.plot([1,2], [1,2], color='blue', label='test')
26+
fig2, axes2 = plt.subplots(1, 1)
27+
axes2.plot([1, 2], [1, 2], color="blue", label="test")
2928
fig2.canvas.draw()
3029

3130

3231
plot_window = UIPlotWindow(
3332
rect=pygame.Rect((350, 275), (300, 200)),
3433
manager=manager,
3534
figuresurface=fig,
36-
resizable=True
35+
resizable=True,
3736
)
3837

3938

40-
41-
4239
plot_window2 = UIPlotWindow(
4340
rect=pygame.Rect((350, 275), (200, 200)),
4441
manager=manager,
4542
figuresurface=fig2,
46-
resizable=False
43+
resizable=False,
4744
)
4845

4946

@@ -52,12 +49,11 @@
5249
is_running = True
5350

5451
while is_running:
55-
time_delta = clock.tick(60)/1000.0
52+
time_delta = clock.tick(60) / 1000.0
5653
for event in pygame.event.get():
5754
if event.type == pygame.QUIT:
5855
is_running = False
5956

60-
6157
manager.process_events(event)
6258

6359
manager.update(time_delta)
@@ -66,7 +62,6 @@
6662
window_surface.blit(background, (0, 0))
6763
manager.draw_ui(window_surface)
6864

69-
7065
# print(plot_window2.get_container().get_size())
7166

7267
pygame.display.update()

examples/save_to_file.py

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
import sys
21
import os
3-
from numpy.ma.core import size
4-
import pygame
5-
62
import matplotlib
7-
matplotlib.use('pygame')
8-
#matplotlib.use('Qt4Agg')
93

10-
import matplotlib.pyplot as plt
11-
import matplotlib.figure as fg
4+
matplotlib.use("pygame")
125

136
import matplotlib.pyplot as plt
7+
148
fig = plt.figure()
159

1610
print(fig.canvas.get_supported_filetypes())
1711

18-
plt.plot([1,2], [1,2], color='green')
19-
plt.text(1.5, 1.5, '2', size=50)
20-
plt.xlabel('swag')
12+
plt.plot([1, 2], [1, 2], color="green")
13+
plt.text(1.5, 1.5, "2", size=50)
14+
plt.xlabel("swag")
2115

22-
plt.savefig('images' + os.sep + 'test.jpg')
23-
plt.savefig('images' + os.sep + 'test.bmp')
24-
plt.savefig('images' + os.sep + 'test2.jpg')
16+
plt.savefig("images" + os.sep + "test.jpg")
17+
plt.savefig("images" + os.sep + "test.bmp")
18+
plt.savefig("images" + os.sep + "test2.jpg")

examples/show.py

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,15 @@
1-
import sys
21
import os
3-
from numpy.ma.core import size
4-
import pygame
52
import numpy as np
63

74
import matplotlib
8-
#matplotlib.use('pygame')
9-
matplotlib.use('pygame')
105

116
import matplotlib.pyplot as plt
12-
import matplotlib.figure as fg
13-
147
import matplotlib.image as mpimg
158

169

10+
matplotlib.use("pygame")
11+
12+
1713
def plot_error_bars_ex(ax):
1814
# example data
1915
x = np.array([0.5, 1.0, 1.5, 2.0, 2.5, 3.0, 3.5, 4.0, 4.5, 5.0])
@@ -24,24 +20,29 @@ def plot_error_bars_ex(ax):
2420
# lower & upper limits of the error
2521
lolims = np.array([0, 0, 1, 0, 1, 0, 0, 0, 1, 0], dtype=bool)
2622
uplims = np.array([0, 1, 0, 0, 0, 1, 0, 0, 0, 1], dtype=bool)
27-
ls = 'dotted'
23+
ls = "dotted"
2824

2925
# standard error bars
3026
ax.errorbar(x, y, xerr=xerr, yerr=yerr, linestyle=ls)
3127

3228
# including upper limits
33-
ax.errorbar(x, y + 0.5, xerr=xerr, yerr=yerr, uplims=uplims,
34-
linestyle=ls)
29+
ax.errorbar(x, y + 0.5, xerr=xerr, yerr=yerr, uplims=uplims, linestyle=ls)
3530

3631
# including lower limits
37-
ax.errorbar(x, y + 1.0, xerr=xerr, yerr=yerr, lolims=lolims,
38-
linestyle=ls)
32+
ax.errorbar(x, y + 1.0, xerr=xerr, yerr=yerr, lolims=lolims, linestyle=ls)
3933

4034
# including upper and lower limits
41-
ax.errorbar(x, y + 1.5, xerr=xerr, yerr=yerr,
42-
lolims=lolims, uplims=uplims,
43-
marker='o', markersize=8,
44-
linestyle=ls)
35+
ax.errorbar(
36+
x,
37+
y + 1.5,
38+
xerr=xerr,
39+
yerr=yerr,
40+
lolims=lolims,
41+
uplims=uplims,
42+
marker="o",
43+
markersize=8,
44+
linestyle=ls,
45+
)
4546

4647
# Plot a series with lower and upper limits in both x & y
4748
# constant x-error with varying y-error
@@ -58,15 +59,23 @@ def plot_error_bars_ex(ax):
5859
uplims[[3]] = True # only limited at this index
5960

6061
# do the plotting
61-
ax.errorbar(x, y + 2.1, xerr=xerr, yerr=yerr,
62-
xlolims=xlolims, xuplims=xuplims,
63-
uplims=uplims, lolims=lolims,
64-
marker='o', markersize=8,
65-
linestyle='none')
62+
ax.errorbar(
63+
x,
64+
y + 2.1,
65+
xerr=xerr,
66+
yerr=yerr,
67+
xlolims=xlolims,
68+
xuplims=xuplims,
69+
uplims=uplims,
70+
lolims=lolims,
71+
marker="o",
72+
markersize=8,
73+
linestyle="none",
74+
)
6675

6776
# tidy up the figure
6877
ax.set_xlim((0, 5.5))
69-
ax.set_title('Errorbar upper and lower limits')
78+
ax.set_title("Errorbar upper and lower limits")
7079

7180

7281
def plot_violin(ax):
@@ -78,60 +87,58 @@ def adjacent_values(vals, q1, q3):
7887
lower_adjacent_value = np.clip(lower_adjacent_value, vals[0], q1)
7988
return lower_adjacent_value, upper_adjacent_value
8089

81-
8290
def set_axis_style(ax, labels):
83-
ax.xaxis.set_tick_params(direction='out')
84-
ax.xaxis.set_ticks_position('bottom')
91+
ax.xaxis.set_tick_params(direction="out")
92+
ax.xaxis.set_ticks_position("bottom")
8593
ax.set_xticks(np.arange(1, len(labels) + 1))
8694
ax.set_xticklabels(labels)
8795
ax.set_xlim(0.25, len(labels) + 0.75)
88-
ax.set_xlabel('Sample name')
89-
96+
ax.set_xlabel("Sample name")
9097

9198
# create test data
9299
np.random.seed(19680801)
93100
data = [sorted(np.random.normal(0, std, 100)) for std in range(1, 5)]
94101

102+
ax.set_title("Customized violin plot")
103+
parts = ax.violinplot(data, showmeans=False, showmedians=False, showextrema=False)
95104

96-
97-
ax.set_title('Customized violin plot')
98-
parts = ax.violinplot(
99-
data, showmeans=False, showmedians=False,
100-
showextrema=False)
101-
102-
for pc in parts['bodies']:
103-
pc.set_facecolor('#D43F3A')
104-
pc.set_edgecolor('black')
105+
for pc in parts["bodies"]:
106+
pc.set_facecolor("#D43F3A")
107+
pc.set_edgecolor("black")
105108
pc.set_alpha(1)
106109

107110
quartile1, medians, quartile3 = np.percentile(data, [25, 50, 75], axis=1)
108-
whiskers = np.array([
109-
adjacent_values(sorted_array, q1, q3)
110-
for sorted_array, q1, q3 in zip(data, quartile1, quartile3)])
111+
whiskers = np.array(
112+
[
113+
adjacent_values(sorted_array, q1, q3)
114+
for sorted_array, q1, q3 in zip(data, quartile1, quartile3)
115+
]
116+
)
111117
whiskers_min, whiskers_max = whiskers[:, 0], whiskers[:, 1]
112118

113119
inds = np.arange(1, len(medians) + 1)
114-
ax.scatter(inds, medians, marker='o', color='white', s=30, zorder=3)
115-
ax.vlines(inds, quartile1, quartile3, color='k', linestyle='-', lw=5)
116-
ax.vlines(inds, whiskers_min, whiskers_max, color='k', linestyle='-', lw=1)
120+
ax.scatter(inds, medians, marker="o", color="white", s=30, zorder=3)
121+
ax.vlines(inds, quartile1, quartile3, color="k", linestyle="-", lw=5)
122+
ax.vlines(inds, whiskers_min, whiskers_max, color="k", linestyle="-", lw=1)
117123

118124
# set style for the axes
119-
labels = ['A', 'B', 'C', 'D']
125+
labels = ["A", "B", "C", "D"]
120126
set_axis_style(ax, labels)
121127

122-
fig, axes = plt.subplots(3,2,figsize=(16, 12))
128+
129+
fig, axes = plt.subplots(3, 2, figsize=(16, 12))
123130
print(type(fig))
124131

125-
axes[0, 0].plot([1,2], [1,2], color='green', label='test')
126-
axes[0, 0].plot([1,2], [1,1], color='orange', lw=5, label='test other larger')
132+
axes[0, 0].plot([1, 2], [1, 2], color="green", label="test")
133+
axes[0, 0].plot([1, 2], [1, 1], color="orange", lw=5, label="test other larger")
127134
# axes[0, 0].legend()
128-
axes[0, 1].text(0.5, 0.5, '2', size=50)
129-
axes[1, 0].set_xlabel('swag')
135+
axes[0, 1].text(0.5, 0.5, "2", size=50)
136+
axes[1, 0].set_xlabel("swag")
130137
axes[1, 0].fill_between([0, 1, 2], [1, 2, 3], [3, 4, 5])
131138
axes[1, 0].scatter([0, 1, 2], [2, 3, 4], s=50)
132-
axes[1, 1].imshow(mpimg.imread('images' + os.sep + 'long_dog.jpg'))
139+
axes[1, 1].imshow(mpimg.imread("images" + os.sep + "long_dog.jpg"))
133140
plot_error_bars_ex(axes[2, 1])
134141

135142
plot_violin(axes[2, 0])
136143

137-
plt.show()
144+
plt.show()

examples/show_in_gameloop.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
1-
2-
31
import matplotlib
4-
matplotlib.use('pygame')
5-
#matplotlib.use('Qt4Agg')
2+
3+
matplotlib.use("pygame")
4+
# matplotlib.use('Qt4Agg')
65

76
import matplotlib.pyplot as plt
87

98
import pygame
109
import pygame.display
1110

12-
fig, axes = plt.subplots(1, 1,)
13-
axes.plot([1,2], [1,2], color='green', label='test')
11+
fig, axes = plt.subplots(1, 1)
12+
axes.plot([1, 2], [1, 2], color="green", label="test")
1413

1514
fig.canvas.draw()
1615

@@ -23,4 +22,4 @@
2322
if event.type == pygame.QUIT:
2423
# Stop showing when quit
2524
show = False
26-
pygame.display.update()
25+
pygame.display.update()

pygame_matplotlib/__init__.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,4 @@
44
def pygame_color_to_plt(color: pygame.Color):
55
"""Convert a pygame Color to a matplot lib value."""
66
# Interval from 0 to 1 in matplotlib
7-
return tuple(
8-
value / 255.0 for value in [color.r, color.g, color.b, color.a]
9-
)
7+
return tuple(value / 255.0 for value in [color.r, color.g, color.b, color.a])

0 commit comments

Comments
 (0)