A matplotlib backend using pygame.
Project description
Pygame Matplotlib Backend
This is an attempt to create a dedicated backend for matplotlib in pygame.
The matplotlib Figure
object is replaced by a FigureSurface
object
which inherits from both matplotlib.figure.Figure
and
pygame.Surface
.
Note that the library is in an experimental developement stage and not all features of standard matplotlib backends are implement at the moment.
Installation
pip install pygame-matplotlib
Usage
First you will need to specify that you want to use pygame backend.
# Select pygame backend
import matplotlib
matplotlib.use('module://pygame_matplotlib.backend_pygame')
Then you can use matplotlib as you usually do.
# Standard matplotlib syntax
import matplotlib.pyplot as plt
fig, ax = plt.subplots() # Create a figure containing a single axes.
ax.plot([1, 2, 3, 4], [1, 4, 2, 3]) # Plot some data on the axes.
plt.show()
Or you can include the plot in your game using the fact that a Figure
is
also a pygame.Surface
with this backend.
import pygame
import pygame.display
fig, axes = plt.subplots(1, 1,)
axes.plot([1,2], [1,2], color='green', label='test')
fig.canvas.draw()
screen = pygame.display.set_mode((800, 600))
# Use the fig as a pygame.Surface
screen.blit(fig, (100, 100))
show = True
while show:
for event in pygame.event.get():
if event.type == pygame.QUIT:
# Stop showing when quit
show = False
pygame.display.update()
Note that if you want to update the plot during the game, you might
need to call fig.canvas.draw()
and screen.blit(fig)
during
the game loop.
See examples in test.py or test_show.py
Current implementation
Support mainly the basic plotting capabilities.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file pygame_matplotlib-0.4.tar.gz
.
File metadata
- Download URL: pygame_matplotlib-0.4.tar.gz
- Upload date:
- Size: 112.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 67e90522f9e9243c17241a38cd725574dc92c4d15129410a58118e037942b6c6 |
|
MD5 | 8ff5b6a535328cb69de816c4547e2c0d |
|
BLAKE2b-256 | 131081366a52cc5ac433b8c4b54f86d5a942123c08b3c3949f492dc6a464a420 |
File details
Details for the file pygame_matplotlib-0.4-py3-none-any.whl
.
File metadata
- Download URL: pygame_matplotlib-0.4-py3-none-any.whl
- Upload date:
- Size: 9.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.9.18
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 6b66a2a7820ef0f933feb96d004e3e157d083dbaa74a703dfa3a06b37f3967af |
|
MD5 | 8d5e090996d57ebd13052b25dc3feb4b |
|
BLAKE2b-256 | 802bd05c5a4b56037cea8fb23893b32568751e2a0c30fb727d9fa9d703516f43 |