Skip to content

Commit ef44a7a

Browse files
committed
Adding new graphics functions from v3.4
1 parent 208465d commit ef44a7a

File tree

1 file changed

+208
-17
lines changed

1 file changed

+208
-17
lines changed

arrayfire/graphics.py

Lines changed: 208 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -140,9 +140,9 @@ def image(self, img, title=None):
140140
_cell = _Cell(self._r, self._c, title, self._cmap)
141141
safe_call(backend.get().af_draw_image(self._wnd, img.arr, ct.pointer(_cell)))
142142

143-
def scatter(self, X, Y, marker=MARKER.POINT, title=None):
143+
def scatter(self, X, Y, Z=None, points=None, marker=MARKER.POINT, title=None):
144144
"""
145-
Renders input arrays as 2D scatter plot.
145+
Renders input arrays as 2D or 3D scatter plot.
146146
147147
Paramters
148148
---------
@@ -153,67 +153,212 @@ def scatter(self, X, Y, marker=MARKER.POINT, title=None):
153153
Y: af.Array.
154154
A 1 dimensional array containing Y co-ordinates.
155155
156+
Z: optional: af.Array. default: None.
157+
- A 1 dimensional array containing Z co-ordinates.
158+
- Not used if line is not None
159+
160+
points: optional: af.Array. default: None.
161+
- A 2 dimensional array of size [n 2]. Each column denotes X and Y co-ordinates for 2D scatter plot.
162+
- A 3 dimensional array of size [n 3]. Each column denotes X, Y, and Z co-ordinates for 3D scatter plot.
163+
164+
marker: af.MARKER
165+
Specifies how the points look
166+
167+
title: str.
168+
Title used for the plot.
169+
"""
170+
_cell = _Cell(self._r, self._c, title, self._cmap)
171+
172+
if points is None:
173+
if Z is None:
174+
safe_call(backend.get().af_draw_scatter_2d(self._wnd, X.arr, Y.arr,
175+
marker.value, ct.pointer(_cell)))
176+
else:
177+
safe_call(backend.get().af_draw_scatter_3d(self._wnd, X.arr, Y.arr, Z.arr,
178+
marker.value, ct.pointer(_cell)))
179+
else:
180+
safe_call(backend.get().af_draw_scatter_nd(self._wnd, points.arr, marker.value, ct.pointer(_cell)))
181+
182+
def scatter2(self, points, marker=MARKER.POINT, title=None):
183+
"""
184+
Renders the input array as a 2D Scatter plot.
185+
186+
Paramters
187+
---------
188+
189+
points: af.Array.
190+
A 2 dimensional array containing (X,Y) co-ordinates.
191+
156192
marker: af.MARKER
157193
Specifies how the points look
158194
159195
title: str.
160196
Title used for the plot.
161197
"""
198+
assert(points.numdims() == 2)
162199
_cell = _Cell(self._r, self._c, title, self._cmap)
163-
safe_call(backend.get().af_draw_scatter(self._wnd, X.arr, Y.arr,
164-
marker.value, ct.pointer(_cell)))
200+
safe_call(backend.get().af_draw_scatter2(self._wnd, points.arr,
201+
marker.value, ct.pointer(_cell)))
165202

166-
def scatter3(self, P, marker=MARKER.POINT, title=None):
203+
def scatter3(self, points, marker=MARKER.POINT, title=None):
167204
"""
168205
Renders the input array as a 3D Scatter plot.
169206
170207
Paramters
171208
---------
172209
173-
P: af.Array.
210+
points: af.Array.
174211
A 2 dimensional array containing (X,Y,Z) co-ordinates.
175212
213+
marker: af.MARKER
214+
Specifies how the points look
215+
176216
title: str.
177217
Title used for the plot.
178218
"""
219+
assert(points.numdims() == 3)
179220
_cell = _Cell(self._r, self._c, title, self._cmap)
180-
safe_call(backend.get().af_draw_scatter3(self._wnd, P.arr,
221+
safe_call(backend.get().af_draw_scatter3(self._wnd, points.arr,
181222
marker.value, ct.pointer(_cell)))
182-
183-
def plot(self, X, Y, title=None):
223+
def plot(self, X, Y, Z=None, line = None, title=None):
184224
"""
185-
Display a 2D Plot.
225+
Display a 2D or 3D Plot.
186226
187227
Paramters
188228
---------
189229
190230
X: af.Array.
191-
A 1 dimensional array containing X co-ordinates.
231+
- A 1 dimensional array containing X co-ordinates.
232+
- Not used if line is not None
192233
193234
Y: af.Array.
194-
A 1 dimensional array containing Y co-ordinates.
235+
- A 1 dimensional array containing Y co-ordinates.
236+
- Not used if line is not None
237+
238+
Z: optional: af.Array. default: None.
239+
- A 1 dimensional array containing Z co-ordinates.
240+
- Not used if line is not None
241+
242+
line: optional: af.Array. default: None.
243+
- A 2 dimensional array of size [n 2]. Each column denotes X and Y co-ordinates for plotting 2D lines.
244+
- A 3 dimensional array of size [n 3]. Each column denotes X, Y, and Z co-ordinates for plotting 3D lines.
195245
196246
title: str.
197247
Title used for the plot.
248+
249+
Note
250+
----
251+
252+
The line parameter takes precedence.
198253
"""
199254
_cell = _Cell(self._r, self._c, title, self._cmap)
200-
safe_call(backend.get().af_draw_plot(self._wnd, X.arr, Y.arr, ct.pointer(_cell)))
255+
if line is None:
256+
if Z is None:
257+
safe_call(backend.get().af_draw_plot_2d(self._wnd, X.arr, Y.arr, ct.pointer(_cell)))
258+
else:
259+
safe_call(backend.get().af_draw_plot_3d(self._wnd, X.arr, Y.arr, Z.arr, ct.pointer(_cell)))
260+
else:
261+
safe_call(backend.get().af_draw_plot_nd(self._wnd, line.arr, ct.pointer(_cell)))
201262

202-
def plot3(self, line, title=None):
263+
def plot2(self, line, title=None):
203264
"""
204-
Renders the input array as a 3D line plot.
265+
Display a 2D Plot.
205266
206267
Paramters
207268
---------
208269
209270
line: af.Array.
210-
A 2 dimensional array containing (X,Y,Z) co-ordinates.
271+
- A 2 dimensional array of size [n 2]. Each column denotes X, and Y co-ordinates for plotting 2D lines.
211272
212273
title: str.
213274
Title used for the plot.
275+
214276
"""
277+
278+
assert(line.numdims() == 2)
215279
_cell = _Cell(self._r, self._c, title, self._cmap)
216-
safe_call(backend.get().af_draw_plot3(self._wnd, line.arr, ct.pointer(_cell)))
280+
safe_call(backend.get().af_draw_plot_nd(self._wnd, line.arr, ct.pointer(_cell)))
281+
282+
def plot3(self, X=None, Y=None, Z=None, line=None, title=None):
283+
"""
284+
Display a 3D Plot.
285+
286+
Paramters
287+
---------
288+
289+
line: af.Array.
290+
- A 3 dimensional array of size [n 3]. Each column denotes X, Y, and Z co-ordinates for plotting 3D lines.
291+
292+
title: str.
293+
Title used for the plot.
294+
"""
295+
296+
assert(line.numdims() == 3)
297+
_cell = _Cell(self._r, self._c, title, self._cmap)
298+
safe_call(backend.get().af_draw_plot_nd(self._wnd, line.arr, ct.pointer(_cell)))
299+
300+
def vector_field(self, xpoints, xdirs, ypoints, ydirs, zpoints=None, zdirs=None,
301+
points = None, dirs = None, title=None):
302+
"""
303+
Display a 2D or 3D Vector_Field.
304+
305+
Paramters
306+
---------
307+
308+
xpoints : af.Array.
309+
- A 1 dimensional array containing X co-ordinates.
310+
- Not used if points is not None
311+
312+
xdirs : af.Array.
313+
- A 1 dimensional array specifying direction at current location.
314+
- Not used if dirs is not None
315+
316+
ypoints : af.Array.
317+
- A 1 dimensional array containing Y co-ordinates.
318+
- Not used if points is not None
319+
320+
ydirs : af.Array.
321+
- A 1 dimensional array specifying direction at current location.
322+
- Not used if dirs is not None
323+
324+
zpoints : optional: af.Array. default: None.
325+
- A 1 dimensional array containing Z co-ordinates.
326+
- Not used if points is not None
327+
328+
zdirs : optional: af.Array. default: none.
329+
- A 1 dimensional array specifying direction at current location.
330+
- Not used if dirs is not None
331+
332+
points : optional: af.Array. default: None.
333+
- A 2 dimensional array of size [n 2]. Each column denotes X and Y co-ordinates for plotting 2D lines.
334+
- A 3 dimensional array of size [n 3]. Each column denotes X, Y, and Z co-ordinates for plotting 3D lines.
335+
336+
dirs : optional: af.Array. default: None.
337+
- A 2 dimensional array of size [n 2]. Each column denotes X and Y directions for plotting 2D lines.
338+
- A 3 dimensional array of size [n 3]. Each column denotes X, Y, and Z directions for plotting 3D lines.
339+
340+
title : str.
341+
Title used for the plot.
342+
343+
Note
344+
----
345+
346+
The line parameter takes precedence.
347+
"""
348+
_cell = _Cell(self._r, self._c, title, self._cmap)
349+
if line is None:
350+
if Z is None:
351+
safe_call(backend.get().af_draw_vector_field_2d(self._wnd,
352+
xpoints.arr, ypoints.arr,
353+
xdirs.arr, ydirs.arr,
354+
ct.pointer(_cell)))
355+
else:
356+
safe_call(backend.get().af_draw_vector_field_2d(self._wnd,
357+
xpoints.arr, ypoints.arr, zpoints.arr,
358+
xdirs.arr, ydirs.arr, zdirs.arr,
359+
ct.pointer(_cell)))
360+
else:
361+
safe_call(backend.get().af_draw_plot_nd(self._wnd, points.arr, dirs.arr, ct.pointer(_cell)))
217362

218363
def surface(self, x_vals, y_vals, z_vals, title=None):
219364
"""
@@ -305,6 +450,52 @@ def set_visibility(is_visible):
305450
"""
306451
safe_call(backend.get().af_set_visibility(self._wnd, is_visible))
307452

453+
def set_axes_limits(self, xmin, xmax, ymin, ymax, zmin=None, zmax=None, exact=False):
454+
"""
455+
Set axis limits.
456+
457+
Paramters
458+
---------
459+
460+
xmin : af.Array.
461+
- lower limit of the x axis.
462+
463+
xmax : af.Array.
464+
- upper limit of the x axis.
465+
466+
ymin : af.Array.
467+
- lower limit of the y axis.
468+
469+
ymax : af.Array.
470+
- upper limit of the y axis.
471+
472+
zmin : optional: af.Array. default: None.
473+
- lower limit of the z axis.
474+
475+
zmax : optional: af.Array. default: None.
476+
- upper limit of the z axis.
477+
478+
title : str.
479+
Title used for the plot.
480+
481+
Note
482+
----
483+
484+
The line parameter takes precedence.
485+
"""
486+
_cell = _Cell(self._r, self._c, "", self._cmap)
487+
if (zmin is None or zmax is None):
488+
safe_call(backend.get().af_set_axes_limits_2d(self._wnd,
489+
ct.c_float(xmin), ct.c_float(xmax),
490+
ct.c_float(ymin), ct.c_float(ymax),
491+
exact, ct.pointer(_cell)))
492+
else:
493+
safe_call(backend.get().af_set_axes_limits_2d(self._wnd,
494+
ct.c_float(xmin), ct.c_float(xmax),
495+
ct.c_float(ymin), ct.c_float(ymax),
496+
ct.c_float(zmin), ct.c_float(zmax),
497+
exact, ct.pointer(_cell)))
498+
308499
def __getitem__(self, keys):
309500
"""
310501
Get access to a specific grid location within the window.

0 commit comments

Comments
 (0)