MCPcopy
hub / github.com/waleedka/hiddenlayer / render

Method render

hiddenlayer/canvas.py:88–145  ·  view source on GitHub ↗
(self)

Source from the content-addressed store, hash-verified

86 self.render()
87
88 def render(self):
89 self._context = "run"
90 # Clear output
91 if 'inline' in self.backend:
92 IPython.display.clear_output(wait=True)
93 self.figure = None
94
95 # Separate the draw_*() calls that generate a grid cell
96 grid_calls = []
97 silent_calls = []
98 for c in self.drawing_calls:
99 if c[0] == "draw_summary":
100 silent_calls.append(c)
101 else:
102 grid_calls.append(c)
103
104 # Header area
105 # TODO: ideally, compute how much header area we need based on the
106 # length of text to show there. Right now, we're just using
107 # a fixed number multiplied by the number of calls. Since there
108 # is only one silent call, draw_summary(), then the header padding
109 # is either 0 or 0.1
110 head_pad = 0.1 * len(silent_calls)
111
112 width = self.theme['fig_width']
113 if not self.figure:
114 self.figure = plt.figure(figsize=(width, width/3 * (head_pad + len(grid_calls))))
115 self.figure.clear()
116
117 # Divide figure area by number of grid calls
118 gs = matplotlib.gridspec.GridSpec(len(grid_calls), 1)
119
120 # Call silent calls
121 for c in silent_calls:
122 getattr(self, c[0])(*c[1], **c[2])
123
124 # Call grid methods
125 for i, c in enumerate(grid_calls):
126 method = c[0]
127 # Create an axis for each call
128 # Save in in self.ax so the drawing function has access to it
129 self.ax = self.figure.add_subplot(gs[i])
130 # Save the GridSpec as well
131 self.gs = gs[i]
132 # Call the method
133 getattr(self, method)(*c[1], **c[2])
134 # Cleanup after drawing
135 self.ax = None
136 self.gs = None
137 gs.tight_layout(self.figure, rect=(0, 0, 1, 1-head_pad))
138
139 # TODO: pause() allows the GUI to render but it's sluggish because it
140 # only has 0.1 seconds of CPU time at each step. A better solution would be to
141 # launch a separate process to render the GUI and pipe data to it.
142 plt.pause(0.1)
143 plt.show(block=False)
144 self.drawing_calls = []
145 self._context = None

Callers 5

__exit__Method · 0.95
wrapperMethod · 0.95
saveMethod · 0.80
test_graphMethod · 0.80
test_graphMethod · 0.80

Calls

no outgoing calls

Tested by 2

test_graphMethod · 0.64
test_graphMethod · 0.64