|
17 | 17 | from matplotlib.lines import Line2D |
18 | 18 | from matplotlib.patches import Rectangle |
19 | 19 | from matplotlib_scalebar.scalebar import ScaleBar |
20 | | -from vispy import scene |
21 | | -from vispy.scene import SceneCanvas |
22 | | -from vispy.app import Timer |
| 20 | + |
23 | 21 | from neuroml import Cell, Segment |
24 | 22 |
|
25 | 23 |
|
26 | 24 | logger = logging.getLogger(__name__) |
27 | 25 | logger.setLevel(logging.INFO) |
28 | 26 |
|
29 | | - |
30 | 27 | VISPY_THEME = { |
31 | 28 | "light": {"bg": "white", "fg": "black"}, |
32 | 29 | "dark": {"bg": "black", "fg": "white"}, |
33 | 30 | } |
34 | 31 | PYNEUROML_VISPY_THEME = "light" |
35 | 32 |
|
| 33 | +try: |
| 34 | + from vispy import scene |
| 35 | + from vispy.scene import SceneCanvas |
| 36 | + from vispy.app import Timer |
| 37 | + |
| 38 | + |
| 39 | + def add_text_to_vispy_3D_plot( |
| 40 | + current_scene: SceneCanvas, |
| 41 | + xv: typing.List[float], |
| 42 | + yv: typing.List[float], |
| 43 | + zv: typing.List[float], |
| 44 | + color: str, |
| 45 | + text: str, |
| 46 | + ): |
| 47 | + """Add text to a vispy plot between two points. |
| 48 | +
|
| 49 | + Wrapper around vispy.scene.visuals.Text |
| 50 | +
|
| 51 | + Rotates the text label to ensure it is at the same angle as the line. |
| 52 | +
|
| 53 | + :param scene: vispy scene object |
| 54 | + :type scene: SceneCanvas |
| 55 | + :param xv: start and end coordinates in one axis |
| 56 | + :type xv: list[x1, x2] |
| 57 | + :param yv: start and end coordinates in second axis |
| 58 | + :type yv: list[y1, y2] |
| 59 | + :param zv: start and end coordinates in third axix |
| 60 | + :type zv: list[z1, z2] |
| 61 | + :param color: color of text |
| 62 | + :type color: str |
| 63 | + :param text: text to write |
| 64 | + :type text: str |
| 65 | + """ |
| 66 | + |
| 67 | + angle = int(numpy.rad2deg(numpy.arctan2((yv[1] - yv[0]), (xv[1] - xv[0])))) |
| 68 | + if angle > 90: |
| 69 | + angle -= 180 |
| 70 | + elif angle < -90: |
| 71 | + angle += 180 |
| 72 | + |
| 73 | + return scene.Text( |
| 74 | + pos=((xv[0] + xv[1]) / 2, (yv[0] + yv[1]) / 2, (zv[0] + zv[1]) / 2), |
| 75 | + text=text, |
| 76 | + color=color, |
| 77 | + rotation=angle, |
| 78 | + parent=current_scene, |
| 79 | + ) |
36 | 80 |
|
37 | | -def add_text_to_vispy_3D_plot( |
38 | | - current_scene: SceneCanvas, |
39 | | - xv: typing.List[float], |
40 | | - yv: typing.List[float], |
41 | | - zv: typing.List[float], |
42 | | - color: str, |
43 | | - text: str, |
44 | | -): |
45 | | - """Add text to a vispy plot between two points. |
46 | | -
|
47 | | - Wrapper around vispy.scene.visuals.Text |
| 81 | +except: |
| 82 | + print("\n**************************\n Please install vispy to use 3D plotting features!\n**************************") |
| 83 | + |
48 | 84 |
|
49 | | - Rotates the text label to ensure it is at the same angle as the line. |
50 | 85 |
|
51 | | - :param scene: vispy scene object |
52 | | - :type scene: SceneCanvas |
53 | | - :param xv: start and end coordinates in one axis |
54 | | - :type xv: list[x1, x2] |
55 | | - :param yv: start and end coordinates in second axis |
56 | | - :type yv: list[y1, y2] |
57 | | - :param zv: start and end coordinates in third axix |
58 | | - :type zv: list[z1, z2] |
59 | | - :param color: color of text |
60 | | - :type color: str |
61 | | - :param text: text to write |
62 | | - :type text: str |
63 | | - """ |
64 | | - angle = int(numpy.rad2deg(numpy.arctan2((yv[1] - yv[0]), (xv[1] - xv[0])))) |
65 | | - if angle > 90: |
66 | | - angle -= 180 |
67 | | - elif angle < -90: |
68 | | - angle += 180 |
69 | 86 |
|
70 | | - return scene.Text( |
71 | | - pos=((xv[0] + xv[1]) / 2, (yv[0] + yv[1]) / 2, (zv[0] + zv[1]) / 2), |
72 | | - text=text, |
73 | | - color=color, |
74 | | - rotation=angle, |
75 | | - parent=current_scene, |
76 | | - ) |
77 | 87 |
|
78 | 88 |
|
79 | 89 | def add_text_to_matplotlib_2D_plot( |
|
0 commit comments