Skip to content

Commit 49e5156

Browse files
author
Roberto De Ioris
authored
Create plotter.py
1 parent c7a507c commit 49e5156

File tree

1 file changed

+36
-0
lines changed
  • tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython_Assets

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import unreal_engine as ue
2+
from unreal_engine.enums import EPixelFormat
3+
4+
import matplotlib
5+
matplotlib.use('Agg')
6+
7+
import matplotlib.pyplot as plt
8+
9+
class PlotComponent:
10+
11+
def begin_play(self):
12+
width = 1024
13+
height = 1024
14+
dpi = 72.0
15+
self.texture = ue.create_transient_texture(width, height, EPixelFormat.PF_R8G8B8A8)
16+
17+
self.uobject.get_owner().StaticMeshComponent.OverrideMaterials[0].set_material_texture_parameter('Graph', self.texture)
18+
19+
self.fig = plt.figure(1)
20+
self.fig.set_dpi(dpi)
21+
self.fig.set_figwidth(width/dpi)
22+
self.fig.set_figheight(height/dpi)
23+
24+
self.uobject.get_owner().bind_event('OnGraphDataUpdated', self.update_graph)
25+
26+
def update_graph(self, platform):
27+
28+
plt.clf()
29+
30+
plt.pie([platform.RedCubeCounter, platform.GreenCubeCounter, platform.BlueCubeCounter], colors=['r', 'g', 'b'], labels=['RedCube', 'GreenCube', 'BlueCube'], shadow=True)
31+
32+
self.fig.canvas.draw()
33+
self.texture.texture_set_data(self.fig.canvas.buffer_rgba())
34+
35+
36+

0 commit comments

Comments
 (0)