pygame-matplotlib


Namepygame-matplotlib JSON
Version 0.4 PyPI version JSON
download
home_page
SummaryA matplotlib backend using pygame.
upload_time2024-01-29 15:18:51
maintainer
docs_urlNone
authorLionel42
requires_python>=3.9
license
keywords backend matplotlib plot pygame
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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.
```python
# Select pygame backend
import matplotlib
matplotlib.use('module://pygame_matplotlib.backend_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

## Current implementation

Support mainly the basic plotting capabilities.


            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pygame-matplotlib",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.9",
    "maintainer_email": "",
    "keywords": "backend,matplotlib,plot,pygame",
    "author": "Lionel42",
    "author_email": "",
    "download_url": "https://files.pythonhosted.org/packages/13/10/81366a52cc5ac433b8c4b54f86d5a942123c08b3c3949f492dc6a464a420/pygame_matplotlib-0.4.tar.gz",
    "platform": null,
    "description": "# Pygame Matplotlib Backend\n\nThis is an attempt to create a dedicated backend for matplotlib\nin pygame.\n\nThe matplotlib ```Figure``` object is replaced by a ```FigureSurface``` object\nwhich inherits from both ```matplotlib.figure.Figure``` and\n```pygame.Surface```.\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('module://pygame_matplotlib.backend_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## Current implementation\n\nSupport mainly the basic plotting capabilities.\n\n",
    "bugtrack_url": null,
    "license": "",
    "summary": "A matplotlib backend using pygame.",
    "version": "0.4",
    "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": "",
            "digests": {
                "blake2b_256": "802bd05c5a4b56037cea8fb23893b32568751e2a0c30fb727d9fa9d703516f43",
                "md5": "8d5e090996d57ebd13052b25dc3feb4b",
                "sha256": "6b66a2a7820ef0f933feb96d004e3e157d083dbaa74a703dfa3a06b37f3967af"
            },
            "downloads": -1,
            "filename": "pygame_matplotlib-0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "8d5e090996d57ebd13052b25dc3feb4b",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.9",
            "size": 9782,
            "upload_time": "2024-01-29T15:18:49",
            "upload_time_iso_8601": "2024-01-29T15:18:49.502887Z",
            "url": "https://files.pythonhosted.org/packages/80/2b/d05c5a4b56037cea8fb23893b32568751e2a0c30fb727d9fa9d703516f43/pygame_matplotlib-0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "131081366a52cc5ac433b8c4b54f86d5a942123c08b3c3949f492dc6a464a420",
                "md5": "8ff5b6a535328cb69de816c4547e2c0d",
                "sha256": "67e90522f9e9243c17241a38cd725574dc92c4d15129410a58118e037942b6c6"
            },
            "downloads": -1,
            "filename": "pygame_matplotlib-0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "8ff5b6a535328cb69de816c4547e2c0d",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.9",
            "size": 112832,
            "upload_time": "2024-01-29T15:18:51",
            "upload_time_iso_8601": "2024-01-29T15:18:51.035181Z",
            "url": "https://files.pythonhosted.org/packages/13/10/81366a52cc5ac433b8c4b54f86d5a942123c08b3c3949f492dc6a464a420/pygame_matplotlib-0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-01-29 15:18:51",
    "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"
}
        
Elapsed time: 0.18150s