MCPcopy Create free account
hub / github.com/plotly/plotly.py / get_streamline_arrows

Method get_streamline_arrows

plotly/figure_factory/_streamline.py:319–394  ·  view source on GitHub ↗

Makes an arrow for each streamline. Gets angle of streamline at 1/3 mark and creates arrow coordinates based off of user defined angle and arrow_scale. :param (array) st_x: x-values for all streamlines :param (array) st_y: y-values for all streamlines

(self)

Source from the content-addressed store, hash-verified

317 self.st_y[index].append(np.nan)
318
319 def get_streamline_arrows(self):
320 """
321 Makes an arrow for each streamline.
322
323 Gets angle of streamline at 1/3 mark and creates arrow coordinates
324 based off of user defined angle and arrow_scale.
325
326 :param (array) st_x: x-values for all streamlines
327 :param (array) st_y: y-values for all streamlines
328 :param (angle in radians) angle: angle of arrowhead. Default = pi/9
329 :param (float in [0,1]) arrow_scale: value to scale length of arrowhead
330 Default = .09
331 :rtype (list, list) arrows_x: x-values to create arrowhead and
332 arrows_y: y-values to create arrowhead
333 """
334 arrow_end_x = np.empty((len(self.st_x)))
335 arrow_end_y = np.empty((len(self.st_y)))
336 arrow_start_x = np.empty((len(self.st_x)))
337 arrow_start_y = np.empty((len(self.st_y)))
338 for index in range(len(self.st_x)):
339 arrow_end_x[index] = self.st_x[index][int(len(self.st_x[index]) / 3)]
340 arrow_start_x[index] = self.st_x[index][
341 (int(len(self.st_x[index]) / 3)) - 1
342 ]
343 arrow_end_y[index] = self.st_y[index][int(len(self.st_y[index]) / 3)]
344 arrow_start_y[index] = self.st_y[index][
345 (int(len(self.st_y[index]) / 3)) - 1
346 ]
347
348 dif_x = arrow_end_x - arrow_start_x
349 dif_y = arrow_end_y - arrow_start_y
350
351 orig_err = np.geterr()
352 np.seterr(divide="ignore", invalid="ignore")
353 streamline_ang = np.arctan(dif_y / dif_x)
354 np.seterr(**orig_err)
355
356 ang1 = streamline_ang + (self.angle)
357 ang2 = streamline_ang - (self.angle)
358
359 seg1_x = np.cos(ang1) * self.arrow_scale
360 seg1_y = np.sin(ang1) * self.arrow_scale
361 seg2_x = np.cos(ang2) * self.arrow_scale
362 seg2_y = np.sin(ang2) * self.arrow_scale
363
364 point1_x = np.empty((len(dif_x)))
365 point1_y = np.empty((len(dif_y)))
366 point2_x = np.empty((len(dif_x)))
367 point2_y = np.empty((len(dif_y)))
368
369 for index in range(len(dif_x)):
370 if dif_x[index] >= 0:
371 point1_x[index] = arrow_end_x[index] - seg1_x[index]
372 point1_y[index] = arrow_end_y[index] - seg1_y[index]
373 point2_x[index] = arrow_end_x[index] - seg2_x[index]
374 point2_y[index] = arrow_end_y[index] - seg2_y[index]
375 else:
376 point1_x[index] = arrow_end_x[index] + seg1_x[index]

Callers 2

__init__Method · 0.95
create_streamlineFunction · 0.80

Calls 3

intFunction · 0.85
tolistMethod · 0.80
arrayMethod · 0.45

Tested by

no test coverage detected