Skip to content

Commit 802a87f

Browse files
committed
work in progress
1 parent c1ed749 commit 802a87f

File tree

2 files changed

+8
-10
lines changed

2 files changed

+8
-10
lines changed

pygame_matplotlib/backend_pygame.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -157,16 +157,12 @@ def draw_text(self, gc, x, y, s, prop, angle, ismath=False, mtext=None):
157157
s, gc.get_antialiased(), [val*255 for val in gc.get_rgb()]
158158
)
159159
if mtext is not None:
160-
mtext.set_verticalalignment('bottom')
161-
mtext.set_horizontalalignment('right')
160+
# Reads the position of the mtext, but could use relative position to 0 instead
162161
x, y, _, _ = mtext.get_window_extent().bounds
163-
# pygame starts from bottom left instead of middle
164-
mtext.set_verticalalignment('center')
165-
mtext.set_horizontalalignment('center')
166-
new_x, new_y, _, _ = mtext.get_window_extent().bounds
167-
print(x, y, new_x, new_y)
168-
y += (new_y - y) * 2
169-
x -= (new_x - x) * 2
162+
width, height = myfont.size(s)
163+
# Needs to resize to center
164+
y += height / 2
165+
x -= width / 2
170166
self.surface.blit(font_surface, (x, self.surface.get_height() - y))
171167

172168
def flipy(self):

test_show.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import matplotlib
77
matplotlib.use('module://pygame_matplotlib.backend_pygame')
8+
#matplotlib.use('Qt4Agg')
89

910
import matplotlib.pyplot as plt
1011
import matplotlib.figure as fg
@@ -15,4 +16,5 @@
1516
ax.text(1.5, 1.5, '2', size=50)
1617
ax.set_xlabel('swag')
1718

18-
fig.show()
19+
20+
plt.show()

0 commit comments

Comments
 (0)