Skip to content

Commit 38653b9

Browse files
author
Roberto De Ioris
authored
Update PlottingGraphsWithMatplotlibAndUnrealEnginePython.md
1 parent f8044a1 commit 38653b9

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython.md

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,41 @@ ue.open_editor_for_asset(texture)
5757
```
5858

5959
![Texture Created](https://github.com/20tab/UnrealEnginePython/blob/master/tutorials/PlottingGraphsWithMatplotlibAndUnrealEnginePython_Assets/texture_created.png)
60+
61+
## Our project: Plotting a Pie chart tracking overlap events
62+
63+
```python
64+
import unreal_engine as ue
65+
from unreal_engine.enums import EPixelFormat
66+
67+
import matplotlib
68+
matplotlib.use('Agg')
69+
70+
import matplotlib.pyplot as plt
71+
72+
class PlotComponent:
73+
74+
def begin_play(self):
75+
width = 1024
76+
height = 1024
77+
dpi = 72.0
78+
self.texture = ue.create_transient_texture(width, height, EPixelFormat.PF_R8G8B8A8)
79+
80+
self.uobject.get_owner().StaticMeshComponent.OverrideMaterials[0].set_material_texture_parameter('Graph', self.texture)
81+
82+
self.fig = plt.figure(1)
83+
self.fig.set_dpi(dpi)
84+
self.fig.set_figwidth(width/dpi)
85+
self.fig.set_figheight(height/dpi)
86+
87+
self.uobject.get_owner().bind_event('OnGraphDataUpdated', self.update_graph)
88+
89+
def update_graph(self, platform):
90+
# clear the current plot data
91+
plt.clf()
92+
# draw a pie chart
93+
plt.pie([platform.RedCubeCounter, platform.GreenCubeCounter, platform.BlueCubeCounter], colors=['r', 'g', 'b'], labels=['RedCube', 'GreenCube', 'BlueCube'], shadow=True)
94+
95+
self.fig.canvas.draw()
96+
self.texture.texture_set_data(self.fig.canvas.buffer_rgba())
97+
```

0 commit comments

Comments
 (0)