Skip to main content

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.

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

pygame-matplotlib-0.2.tar.gz (7.1 kB view details)

Uploaded Source

Built Distribution

pygame_matplotlib-0.2-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

Details for the file pygame-matplotlib-0.2.tar.gz.

File metadata

  • Download URL: pygame-matplotlib-0.2.tar.gz
  • Upload date:
  • Size: 7.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0

File hashes

Hashes for pygame-matplotlib-0.2.tar.gz
Algorithm Hash digest
SHA256 9147af28cd68840cec7db1d0ce86da9317553ba8426cd1332c55824cf37b8528
MD5 891870c6911ebaf841888351fd57e1d4
BLAKE2b-256 4a0345ba3ec9581c5449f0d515e7bc3caada097930c429ec5b3ae1101ee71246

See more details on using hashes here.

File details

Details for the file pygame_matplotlib-0.2-py3-none-any.whl.

File metadata

  • Download URL: pygame_matplotlib-0.2-py3-none-any.whl
  • Upload date:
  • Size: 7.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.0

File hashes

Hashes for pygame_matplotlib-0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6f73296ee383cd14c31dcc974bd04913a58ce7c301cd20f67cd55ec993d92a80
MD5 475f371e7b60297725fcb9b615d9d7de
BLAKE2b-256 d4dc773bb82cfab16942c8b215c64c5189e511f3f311af538e750f38612e42b3

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page