Skip to content

Commit

Permalink
make matplotlib backend customizable
Browse files Browse the repository at this point in the history
  • Loading branch information
misko committed Oct 8, 2024
1 parent eeadfca commit b653b20
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 16 deletions.
1 change: 0 additions & 1 deletion hudes/hudes_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,6 @@ def run_loop(self):
self.view.draw()
logging.debug("hudes_client: redraw done")
else:

logging.debug("hudes_client: sleep")
sleep(0.01)
logging.debug("hudes_client: sleep up")
Expand Down
21 changes: 6 additions & 15 deletions hudes/view.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,21 @@

from hudes.opengl_func import (
create_grid_indices,
create_grid_points,
create_grid_points_with_colors,
create_matplotlib_texture,
create_matplotlib_texture_rgba,
create_surface_grid_indices,
create_surface_grid_points,
create_texture,
create_texture_rgba,
draw_arrow,
draw_red_plane,
draw_red_sphere,
render_text,
render_text_2d,
render_texture,
render_texture_rgba,
update_grid_cbo,
update_grid_vbo,
)

matplotlib.use("Agg")

import time

import matplotlib.backends.backend_agg as agg
import matplotlib.pyplot as plt
import numpy as np
import pygame as pg
Expand Down Expand Up @@ -165,6 +156,9 @@ def __init__(self, use_midi=False):
figsize=(12, 8),
)

# self.canvas = agg.FigureCanvasAgg(self.fig)
self.canvas = self.fig.canvas
self.renderer = self.canvas.get_renderer()
self.fig.subplots_adjust(
left=0.07, right=0.95, hspace=0.8, top=0.92, bottom=0.07, wspace=0.5 # 0.5
)
Expand Down Expand Up @@ -296,11 +290,9 @@ def plot_train_and_val(
self.axd["D"].set_xlabel("Step")

def draw(self):
canvas = agg.FigureCanvasAgg(self.fig)
canvas.draw()
surf = pg.image.frombytes(
canvas.get_renderer().tostring_rgb(), self.window_size, "RGB"
)

self.canvas.draw()
surf = pg.image.frombytes(self.renderer.tostring_rgb(), self.window_size, "RGB")
self.screen.blit(surf, (0, 0))
pg.display.flip() # draws whole screen vs update that draws a parts

Expand Down Expand Up @@ -451,7 +443,6 @@ def __init__(self, grid_size, grids):
# init plt
plt.style.use("dark_background")
self.fig = plt.figure(figsize=(12, 2), facecolor="none")

self.fig.subplots_adjust(
left=0.07, right=0.95, hspace=0.8, top=0.80, bottom=0.1, wspace=0.5 # 0.5
)
Expand Down

0 comments on commit b653b20

Please sign in to comment.