# Pygame Matplotlib Backend
Create plots in pygame.
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.
```python
# Select pygame backend
import matplotlib
matplotlib.use('pygame')
```
Then you can use matplotlib as you usually do.
```python
# 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.
```python
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
## How it works in the back
The matplotlib ```Figure``` object is replaced by a ```FigureSurface``` object
which inherits from both ```matplotlib.figure.Figure``` and
```pygame.Surface```.
## Current implementation
Support mainly the basic plotting capabilities.
Raw data
{
"_id": null,
"home_page": null,
"name": "pygame-matplotlib",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.9",
"maintainer_email": null,
"keywords": "backend, matplotlib, plot, pygame",
"author": "Lionel42",
"author_email": null,
"download_url": "https://files.pythonhosted.org/packages/46/5c/fc7aaf8ea6683318427b9854f151d794168f1cef860c382d4ef8c9e39b00/pygame_matplotlib-0.5.tar.gz",
"platform": null,
"description": "# Pygame Matplotlib Backend\n\nCreate plots in pygame.\n\n\nNote that the library is in an experimental developement stage and not\nall features of standard matplotlib backends are implement at the moment.\n\n## Installation\n```\npip install pygame-matplotlib\n```\n\n## Usage\n\nFirst you will need to specify that you want to use pygame backend.\n```python\n# Select pygame backend\nimport matplotlib\nmatplotlib.use('pygame')\n```\n\nThen you can use matplotlib as you usually do.\n```python\n# Standard matplotlib syntax\nimport matplotlib.pyplot as plt\nfig, ax = plt.subplots() # Create a figure containing a single axes.\nax.plot([1, 2, 3, 4], [1, 4, 2, 3]) # Plot some data on the axes.\nplt.show()\n```\n\nOr you can include the plot in your game using the fact that a ```Figure``` is\nalso a ```pygame.Surface``` with this backend.\n```python\nimport pygame\nimport pygame.display\n\nfig, axes = plt.subplots(1, 1,)\naxes.plot([1,2], [1,2], color='green', label='test')\n\nfig.canvas.draw()\n\nscreen = pygame.display.set_mode((800, 600))\n\n# Use the fig as a pygame.Surface\nscreen.blit(fig, (100, 100))\n\nshow = True\nwhile show:\n for event in pygame.event.get():\n if event.type == pygame.QUIT:\n # Stop showing when quit\n show = False\n pygame.display.update()\n```\n\nNote that if you want to update the plot during the game, you might\nneed to call ```fig.canvas.draw()``` and ```screen.blit(fig)``` during\nthe game loop.\n\nSee examples in test.py or test_show.py\n\n\n## How it works in the back\n\nThe matplotlib ```Figure``` object is replaced by a ```FigureSurface``` object\nwhich inherits from both ```matplotlib.figure.Figure``` and\n```pygame.Surface```.\n\n\n## Current implementation\n\nSupport mainly the basic plotting capabilities.\n\n",
"bugtrack_url": null,
"license": null,
"summary": "A matplotlib backend using pygame.",
"version": "0.5",
"project_urls": {
"Homepage": "https://github.com/lionel42/pygame-matplotlib-backend",
"Repository": "https://github.com/lionel42/pygame-matplotlib-backend"
},
"split_keywords": [
"backend",
" matplotlib",
" plot",
" pygame"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "d7608d4608440ec841247a9612d94d24052fe5189c865580fd35ea53060c0424",
"md5": "a1e949ec99b084c56b92639ada5826d2",
"sha256": "6e04ab3950e8ecd3b43aa6c1ac9a56a9c6a573d5dfcf226ab03622497763e76c"
},
"downloads": -1,
"filename": "pygame_matplotlib-0.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a1e949ec99b084c56b92639ada5826d2",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.9",
"size": 10669,
"upload_time": "2025-07-28T19:46:16",
"upload_time_iso_8601": "2025-07-28T19:46:16.541953Z",
"url": "https://files.pythonhosted.org/packages/d7/60/8d4608440ec841247a9612d94d24052fe5189c865580fd35ea53060c0424/pygame_matplotlib-0.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "465cfc7aaf8ea6683318427b9854f151d794168f1cef860c382d4ef8c9e39b00",
"md5": "e874f5e5a10611a0f14c34fdfbda3ab3",
"sha256": "98d78e05dc1c8e508f3e9c37665aaf94856dd0cad4610fb69575cd53ee2b3292"
},
"downloads": -1,
"filename": "pygame_matplotlib-0.5.tar.gz",
"has_sig": false,
"md5_digest": "e874f5e5a10611a0f14c34fdfbda3ab3",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.9",
"size": 118557,
"upload_time": "2025-07-28T19:46:17",
"upload_time_iso_8601": "2025-07-28T19:46:17.742853Z",
"url": "https://files.pythonhosted.org/packages/46/5c/fc7aaf8ea6683318427b9854f151d794168f1cef860c382d4ef8c9e39b00/pygame_matplotlib-0.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-07-28 19:46:17",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "lionel42",
"github_project": "pygame-matplotlib-backend",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "pygame-matplotlib"
}