Coverage for nilearn/plotting/displays/_projectors.py: 0%

115 statements  

« prev     ^ index     » next       coverage.py v7.9.1, created at 2025-06-16 12:32 +0200

1import warnings 

2from typing import ClassVar 

3 

4import matplotlib.pyplot as plt 

5import numpy as np 

6from matplotlib import cm as mpl_cm 

7from scipy.sparse import issparse 

8from scipy.stats import scoreatpercentile 

9 

10from nilearn import DEFAULT_DIVERGING_CMAP 

11from nilearn._utils.logger import find_stack_level 

12from nilearn._utils.param_validation import check_threshold 

13from nilearn.plotting.displays._axes import GlassBrainAxes 

14from nilearn.plotting.displays._slicers import OrthoSlicer 

15from nilearn.plotting.displays._utils import get_create_display_fun 

16 

17 

18class OrthoProjector(OrthoSlicer): 

19 """A class to create linked axes for plotting orthogonal projections \ 

20 of 3D maps. 

21 

22 This visualization mode can be activated from 

23 :func:`~nilearn.plotting.plot_glass_brain`, by setting 

24 ``display_mode='ortho'``: 

25 

26 .. code-block:: python 

27 

28 from nilearn.datasets import load_mni152_template 

29 from nilearn.plotting import plot_glass_brain 

30 

31 img = load_mni152_template() 

32 # display is an instance of the OrthoProjector class 

33 display = plot_glass_brain(img, display_mode="ortho") 

34 

35 Attributes 

36 ---------- 

37 axes : :obj:`dict` of :class:`~nilearn.plotting.displays.GlassBrainAxes` 

38 The 3 axes used to plot each view ('x', 'y', and 'z'). 

39 

40 frame_axes : :class:`~matplotlib.axes.Axes` 

41 The axes framing the whole set of views. 

42 

43 """ 

44 

45 _axes_class = GlassBrainAxes # type: ignore[assignment] 

46 

47 @classmethod 

48 def find_cut_coords( 

49 cls, 

50 img=None, # noqa: ARG003 

51 threshold=None, # noqa: ARG003 

52 cut_coords=None, # noqa: ARG003 

53 ): 

54 """Find the coordinates of the cut.""" 

55 return (None,) * len(cls._cut_displayed) 

56 

57 def draw_cross(self, cut_coords=None, **kwargs): 

58 """Do nothing. 

59 

60 It does not make sense to draw crosses for the position of 

61 the cuts since we are taking the max along one axis. 

62 """ 

63 pass 

64 

65 def _check_inputs_add_graph( 

66 self, 

67 adjacency_matrix, 

68 node_coords, 

69 node_color, 

70 node_kwargs, 

71 ): 

72 """Perform the input checks and raise different types of errors. 

73 

74 ``_check_inputs_add_graph`` is called inside the method ``add_graph``. 

75 """ 

76 # safety checks 

77 if "s" in node_kwargs: 

78 raise ValueError( 

79 "Please use 'node_size' and not 'node_kwargs' " 

80 "to specify node sizes." 

81 ) 

82 if "c" in node_kwargs: 

83 raise ValueError( 

84 "Please use 'node_color' and not 'node_kwargs' " 

85 "to specify node colors." 

86 ) 

87 

88 adjacency_matrix_shape = adjacency_matrix.shape 

89 if ( 

90 len(adjacency_matrix_shape) != 2 

91 or adjacency_matrix_shape[0] != adjacency_matrix_shape[1] 

92 ): 

93 raise ValueError( 

94 "'adjacency_matrix' is supposed to have shape (n, n)." 

95 f" Its shape was {adjacency_matrix_shape}." 

96 ) 

97 

98 node_coords_shape = node_coords.shape 

99 if len(node_coords_shape) != 2 or node_coords_shape[1] != 3: 

100 message = ( 

101 "Invalid shape for 'node_coords'. " 

102 "You passed an 'adjacency_matrix' " 

103 f"of shape {adjacency_matrix_shape} " 

104 "therefore 'node_coords' should be a array " 

105 f"with shape ({adjacency_matrix_shape[0]}, 3) " 

106 f"while its shape was {node_coords_shape}." 

107 ) 

108 

109 raise ValueError(message) 

110 

111 if ( 

112 isinstance(node_color, (list, np.ndarray)) 

113 and len(node_color) != 1 

114 and len(node_color) != node_coords_shape[0] 

115 ): 

116 raise ValueError( 

117 "Mismatch between the number of nodes " 

118 f"({node_coords_shape[0]}) " 

119 f"and the number of node colors ({len(node_color)})." 

120 ) 

121 

122 if node_coords_shape[0] != adjacency_matrix_shape[0]: 

123 raise ValueError( 

124 "Shape mismatch between 'adjacency_matrix' " 

125 "and 'node_coords'." 

126 f"'adjacency_matrix' shape is {adjacency_matrix_shape}, " 

127 f"'node_coords' shape is {node_coords_shape}." 

128 ) 

129 

130 def add_graph( 

131 self, 

132 adjacency_matrix, 

133 node_coords, 

134 node_color="auto", 

135 node_size=50, 

136 edge_cmap=DEFAULT_DIVERGING_CMAP, 

137 edge_vmin=None, 

138 edge_vmax=None, 

139 edge_threshold=None, 

140 edge_kwargs=None, 

141 node_kwargs=None, 

142 colorbar=False, 

143 ): 

144 """Plot undirected graph on each of the axes. 

145 

146 Parameters 

147 ---------- 

148 adjacency_matrix : :class:`numpy.ndarray` of shape ``(n, n)`` 

149 Represents the edges strengths of the graph. 

150 The matrix can be symmetric which will result in 

151 an undirected graph, or not symmetric which will 

152 result in a directed graph. 

153 

154 node_coords : :class:`numpy.ndarray` of shape ``(n, 3)`` 

155 3D coordinates of the graph nodes in world space. 

156 

157 node_color : color or sequence of colors, default='auto' 

158 Color(s) of the nodes. 

159 

160 node_size : scalar or array_like, default=50 

161 Size(s) of the nodes in points^2. 

162 

163 edge_cmap : :class:`~matplotlib.colors.Colormap`, default="RdBu_r" 

164 Colormap used for representing the strength of the edges. 

165 

166 edge_vmin, edge_vmax : :obj:`float`, optional 

167 - If not ``None``, either or both of these values will be used 

168 to as the minimum and maximum values to color edges. 

169 - If ``None`` are supplied, the maximum absolute value within the 

170 given threshold will be used as minimum (multiplied by -1) and 

171 maximum coloring levels. 

172 

173 edge_threshold : :obj:`str` or :obj:`int` or :obj:`float`, optional 

174 - If it is a number only the edges with a value greater than 

175 ``edge_threshold`` will be shown. 

176 - If it is a string it must finish with a percent sign, 

177 e.g. "25.3%", and only the edges with a abs(value) above 

178 the given percentile will be shown. 

179 

180 edge_kwargs : :obj:`dict`, optional 

181 Will be passed as kwargs for each edge 

182 :class:`~matplotlib.lines.Line2D`. 

183 

184 node_kwargs : :obj:`dict` 

185 Will be passed as kwargs to the function 

186 :func:`~matplotlib.pyplot.scatter` which plots all the 

187 nodes at one. 

188 """ 

189 # set defaults 

190 edge_kwargs = edge_kwargs or {} 

191 node_kwargs = node_kwargs or {} 

192 if isinstance(node_color, str) and node_color == "auto": 

193 node_color = mpl_cm.Set2(np.linspace(0, 1, len(node_coords))) 

194 node_coords = np.asarray(node_coords) 

195 

196 # decompress input matrix if sparse 

197 if issparse(adjacency_matrix): 

198 adjacency_matrix = adjacency_matrix.toarray() 

199 

200 # make the lines below well-behaved 

201 adjacency_matrix = np.nan_to_num(adjacency_matrix) 

202 

203 self._check_inputs_add_graph( 

204 adjacency_matrix, node_coords, node_color, node_kwargs 

205 ) 

206 

207 # If the adjacency matrix is not symmetric, give a warning 

208 symmetric = True 

209 if not np.allclose(adjacency_matrix, adjacency_matrix.T, rtol=1e-3): 

210 symmetric = False 

211 warnings.warn( 

212 "'adjacency_matrix' is not symmetric.\n" 

213 "A directed graph will be plotted.", 

214 stacklevel=find_stack_level(), 

215 ) 

216 

217 # For a masked array, masked values are replaced with zeros 

218 if hasattr(adjacency_matrix, "mask"): 

219 if not (adjacency_matrix.mask == adjacency_matrix.mask.T).all(): 

220 symmetric = False 

221 warnings.warn( 

222 "'adjacency_matrix' was masked \ 

223 with a non symmetric mask.\n" 

224 "A directed graph will be plotted.", 

225 stacklevel=find_stack_level(), 

226 ) 

227 adjacency_matrix = adjacency_matrix.filled(0) 

228 

229 if edge_threshold is not None: 

230 if symmetric: 

231 # Keep a percentile of edges with the highest absolute 

232 # values, so only need to look at the covariance 

233 # coefficients below the diagonal 

234 lower_diagonal_indices = np.tril_indices_from( 

235 adjacency_matrix, k=-1 

236 ) 

237 lower_diagonal_values = adjacency_matrix[ 

238 lower_diagonal_indices 

239 ] 

240 edge_threshold = check_threshold( 

241 edge_threshold, 

242 np.abs(lower_diagonal_values), 

243 scoreatpercentile, 

244 "edge_threshold", 

245 ) 

246 else: 

247 edge_threshold = check_threshold( 

248 edge_threshold, 

249 np.abs(adjacency_matrix.ravel()), 

250 scoreatpercentile, 

251 "edge_threshold", 

252 ) 

253 

254 adjacency_matrix = adjacency_matrix.copy() 

255 threshold_mask = np.abs(adjacency_matrix) < edge_threshold 

256 adjacency_matrix[threshold_mask] = 0 

257 

258 if symmetric: 

259 lower_triangular_adjacency_matrix = np.tril(adjacency_matrix, k=-1) 

260 non_zero_indices = lower_triangular_adjacency_matrix.nonzero() 

261 else: 

262 non_zero_indices = adjacency_matrix.nonzero() 

263 

264 line_coords = [ 

265 node_coords[list(index)] for index in zip(*non_zero_indices) 

266 ] 

267 

268 adjacency_matrix_values = adjacency_matrix[non_zero_indices] 

269 for ax in self.axes.values(): 

270 ax._add_markers(node_coords, node_color, node_size, **node_kwargs) 

271 if line_coords: 

272 ax._add_lines( 

273 line_coords, 

274 adjacency_matrix_values, 

275 edge_cmap, 

276 vmin=edge_vmin, 

277 vmax=edge_vmax, 

278 directed=(not symmetric), 

279 **edge_kwargs, 

280 ) 

281 # To obtain the brain left view, we simply invert the x axis 

282 if ax.direction == "l" and not ( 

283 ax.ax.get_xlim()[0] > ax.ax.get_xlim()[1] 

284 ): 

285 ax.ax.invert_xaxis() 

286 

287 if colorbar: 

288 self._colorbar = colorbar 

289 self._show_colorbar(ax.cmap, ax.norm, threshold=edge_threshold) 

290 

291 plt.draw_if_interactive() 

292 

293 

294class XProjector(OrthoProjector): 

295 """The ``XProjector`` class enables sagittal visualization through 2D \ 

296 projections with :func:`~nilearn.plotting.plot_glass_brain`. 

297 

298 This visualization mode can be activated by setting ``display_mode='x'``: 

299 

300 .. code-block:: python 

301 

302 from nilearn.datasets import load_mni152_template 

303 from nilearn.plotting import plot_glass_brain 

304 

305 img = load_mni152_template() 

306 # display is an instance of the XProjector class 

307 display = plot_glass_brain(img, display_mode="x") 

308 

309 Attributes 

310 ---------- 

311 axes : :obj:`dict` of :class:`~nilearn.plotting.displays.GlassBrainAxes` 

312 The axes used for plotting. 

313 

314 frame_axes : :class:`~matplotlib.axes.Axes` 

315 The axes framing the whole set of views. 

316 

317 See Also 

318 -------- 

319 nilearn.plotting.displays.YProjector : Coronal view 

320 nilearn.plotting.displays.ZProjector : Axial view 

321 

322 """ 

323 

324 _cut_displayed: ClassVar[str] = "x" 

325 _default_figsize: ClassVar[list[float]] = [2.6, 3.0] 

326 

327 

328class YProjector(OrthoProjector): 

329 """The ``YProjector`` class enables coronal visualization through 2D \ 

330 projections with :func:`~nilearn.plotting.plot_glass_brain`. 

331 

332 This visualization mode can be activated by setting ``display_mode='y'``: 

333 

334 .. code-block:: python 

335 

336 from nilearn.datasets import load_mni152_template 

337 from nilearn.plotting import plot_glass_brain 

338 

339 img = load_mni152_template() 

340 # display is an instance of the YProjector class 

341 display = plot_glass_brain(img, display_mode="y") 

342 

343 Attributes 

344 ---------- 

345 axes : :obj:`dict` of :class:`~nilearn.plotting.displays.GlassBrainAxes` 

346 The axes used for plotting. 

347 

348 frame_axes : :class:`~matplotlib.axes.Axes` 

349 The axes framing the whole set of views. 

350 

351 See Also 

352 -------- 

353 nilearn.plotting.displays.XProjector : Sagittal view 

354 nilearn.plotting.displays.ZProjector : Axial view 

355 

356 """ 

357 

358 _cut_displayed: ClassVar[str] = "y" 

359 _default_figsize: ClassVar[list[float]] = [2.2, 3.0] 

360 

361 

362class ZProjector(OrthoProjector): 

363 """The ``ZProjector`` class enables axial visualization through 2D \ 

364 projections with :func:`~nilearn.plotting.plot_glass_brain`. 

365 

366 This visualization mode can be activated by setting ``display_mode='z'``: 

367 

368 .. code-block:: python 

369 

370 from nilearn.datasets import load_mni152_template 

371 from nilearn.plotting import plot_glass_brain 

372 

373 img = load_mni152_template() 

374 # display is an instance of the ZProjector class 

375 display = plot_glass_brain(img, display_mode="z") 

376 

377 Attributes 

378 ---------- 

379 axes : :obj:`dict` of :class:`~nilearn.plotting.displays.GlassBrainAxes` 

380 The axes used for plotting. 

381 

382 frame_axes : :class:`~matplotlib.axes.Axes` 

383 The axes framing the whole set of views. 

384 

385 See Also 

386 -------- 

387 nilearn.plotting.displays.XProjector : Sagittal view 

388 nilearn.plotting.displays.YProjector : Coronal view 

389 

390 """ 

391 

392 _cut_displayed: ClassVar[str] = "z" 

393 _default_figsize: ClassVar[list[float]] = [2.2, 3.4] 

394 

395 

396class XZProjector(OrthoProjector): 

397 """The ``XZProjector`` class enables to combine sagittal \ 

398 and axial views \ 

399 on the same figure through 2D projections with \ 

400 :func:`~nilearn.plotting.plot_glass_brain`. 

401 

402 This visualization mode 

403 can be activated by setting ``display_mode='xz'``: 

404 

405 .. code-block:: python 

406 

407 from nilearn.datasets import load_mni152_template 

408 from nilearn.plotting import plot_glass_brain 

409 

410 img = load_mni152_template() 

411 # display is an instance of the XZProjector class 

412 display = plot_glass_brain(img, display_mode="xz") 

413 

414 Attributes 

415 ---------- 

416 axes : :obj:`dict` of :class:`~nilearn.plotting.displays.GlassBrainAxes` 

417 The axes used for plotting in each direction ('x' and 'z' here). 

418 

419 frame_axes : :class:`~matplotlib.axes.Axes` 

420 The axes framing the whole set of views. 

421 

422 See Also 

423 -------- 

424 nilearn.plotting.displays.YXProjector : Coronal + Sagittal views 

425 nilearn.plotting.displays.YZProjector : Coronal + Axial views 

426 

427 """ 

428 

429 _cut_displayed = "xz" 

430 

431 

432class YXProjector(OrthoProjector): 

433 """The ``YXProjector`` class enables to combine coronal \ 

434 and sagittal views \ 

435 on the same figure through 2D projections with \ 

436 :func:`~nilearn.plotting.plot_glass_brain`. 

437 

438 This visualization mode 

439 can be activated by setting ``display_mode='yx'``: 

440 

441 .. code-block:: python 

442 

443 from nilearn.datasets import load_mni152_template 

444 from nilearn.plotting import plot_glass_brain 

445 

446 img = load_mni152_template() 

447 # display is an instance of the YXProjector class 

448 display = plot_glass_brain(img, display_mode="yx") 

449 

450 Attributes 

451 ---------- 

452 axes : :obj:`dict` of :class:`~nilearn.plotting.displays.GlassBrainAxes` 

453 The axes used for plotting in each direction ('x' and 'y' here). 

454 

455 frame_axes : :class:`~matplotlib.axes.Axes` 

456 The axes framing the whole set of views. 

457 

458 See Also 

459 -------- 

460 nilearn.plotting.displays.XZProjector : Sagittal + Axial views 

461 nilearn.plotting.displays.YZProjector : Coronal + Axial views 

462 

463 """ 

464 

465 _cut_displayed = "yx" 

466 

467 

468class YZProjector(OrthoProjector): 

469 """The ``YZProjector`` class enables to combine coronal and axial views \ 

470 on the same figure through 2D projections with \ 

471 :func:`~nilearn.plotting.plot_glass_brain`. 

472 

473 This visualization mode 

474 can be activated by setting ``display_mode='yz'``: 

475 

476 .. code-block:: python 

477 

478 from nilearn.datasets import load_mni152_template 

479 from nilearn.plotting import plot_glass_brain 

480 

481 img = load_mni152_template() 

482 # display is an instance of the YZProjector class 

483 display = plot_glass_brain(img, display_mode="yz") 

484 

485 Attributes 

486 ---------- 

487 axes : :obj:`dict` of :class:`~nilearn.plotting.displays.GlassBrainAxes` 

488 The axes used for plotting in each direction ('y' and 'z' here). 

489 

490 frame_axes : :class:`~matplotlib.axes.Axes` 

491 The axes framing the whole set of views. 

492 

493 See Also 

494 -------- 

495 nilearn.plotting.displays.XZProjector : Sagittal + Axial views 

496 nilearn.plotting.displays.YXProjector : Coronal + Sagittal views 

497 

498 """ 

499 

500 _cut_displayed: ClassVar[str] = "yz" 

501 _default_figsize: ClassVar[list[float]] = [2.2, 3.4] 

502 

503 

504class LYRZProjector(OrthoProjector): 

505 """The ``LYRZProjector`` class enables ? visualization \ 

506 on the same figure through 2D projections with \ 

507 :func:`~nilearn.plotting.plot_glass_brain`. 

508 

509 This visualization mode 

510 can be activated by setting ``display_mode='lyrz'``: 

511 

512 .. code-block:: python 

513 

514 from nilearn.datasets import load_mni152_template 

515 from nilearn.plotting import plot_glass_brain 

516 

517 img = load_mni152_template() 

518 # display is an instance of the LYRZProjector class 

519 display = plot_glass_brain(img, display_mode="lyrz") 

520 

521 Attributes 

522 ---------- 

523 axes : :obj:`dict` of :class:`~nilearn.plotting.displays.GlassBrainAxes` 

524 The axes used for plotting in each direction ('l', 'y', 'r', 

525 and 'z' here). 

526 

527 frame_axes : :class:`~matplotlib.axes.Axes` 

528 The axes framing the whole set of views. 

529 

530 See Also 

531 -------- 

532 nilearn.plotting.displays.LZRYProjector : ?? views 

533 

534 """ 

535 

536 _cut_displayed = "lyrz" 

537 

538 

539class LZRYProjector(OrthoProjector): 

540 """The ``LZRYProjector`` class enables ? visualization \ 

541 on the same figure through 2D projections with \ 

542 :func:`~nilearn.plotting.plot_glass_brain`. 

543 

544 This visualization mode 

545 can be activated by setting ``display_mode='lzry'``: 

546 

547 .. code-block:: python 

548 

549 from nilearn.datasets import load_mni152_template 

550 from nilearn.plotting import plot_glass_brain 

551 

552 img = load_mni152_template() 

553 # display is an instance of the LZRYProjector class 

554 display = plot_glass_brain(img, display_mode="lzry") 

555 

556 Attributes 

557 ---------- 

558 axes : :obj:`dict` of :class:`~nilearn.plotting.displays.GlassBrainAxes` 

559 The axes used for plotting in each direction ('l', 'z', 'r', 

560 and 'y' here). 

561 

562 frame_axes : :class:`~matplotlib.axes.Axes` 

563 The axes framing the whole set of views. 

564 

565 See Also 

566 -------- 

567 nilearn.plotting.displays.LYRZProjector : ?? views 

568 

569 """ 

570 

571 _cut_displayed = "lzry" 

572 

573 

574class LZRProjector(OrthoProjector): 

575 """The ``LZRProjector`` class enables hemispheric sagittal visualization \ 

576 on the same figure through 2D projections with \ 

577 :func:`~nilearn.plotting.plot_glass_brain`. 

578 

579 This visualization mode 

580 can be activated by setting ``display_mode='lzr'``: 

581 

582 .. code-block:: python 

583 

584 from nilearn.datasets import load_mni152_template 

585 from nilearn.plotting import plot_glass_brain 

586 

587 img = load_mni152_template() 

588 # display is an instance of the LZRProjector class 

589 display = plot_glass_brain(img, display_mode="lzr") 

590 

591 Attributes 

592 ---------- 

593 axes : :obj:`dict` of :class:`~nilearn.plotting.displays.GlassBrainAxes` 

594 The axes used for plotting in each direction ('l', 'z' and 'r' here). 

595 

596 frame_axes : :class:`~matplotlib.axes.Axes` 

597 The axes framing the whole set of views. 

598 

599 See Also 

600 -------- 

601 nilearn.plotting.displays.LYRProjector : ?? views 

602 

603 """ 

604 

605 _cut_displayed = "lzr" 

606 

607 

608class LYRProjector(OrthoProjector): 

609 """The ``LYRProjector`` class enables ? visualization \ 

610 on the same figure through 2D projections with \ 

611 :func:`~nilearn.plotting.plot_glass_brain`. 

612 

613 This visualization mode 

614 can be activated by setting ``display_mode='lyr'``: 

615 

616 .. code-block:: python 

617 

618 from nilearn.datasets import load_mni152_template 

619 from nilearn.plotting import plot_glass_brain 

620 

621 img = load_mni152_template() 

622 # display is an instance of the LYRProjector class 

623 display = plot_glass_brain(img, display_mode="lyr") 

624 

625 Attributes 

626 ---------- 

627 axes : :obj:`dict` of :class:`~nilearn.plotting.displays.GlassBrainAxes` 

628 The axes used for plotting in each direction ('l', 'y' and 'r' here). 

629 

630 frame_axes : :class:`~matplotlib.axes.Axes` 

631 The axes framing the whole set of views. 

632 

633 See Also 

634 -------- 

635 nilearn.plotting.displays.LZRProjector : ?? views 

636 

637 """ 

638 

639 _cut_displayed = "lyr" 

640 

641 

642class LRProjector(OrthoProjector): 

643 """The ``LRProjector`` class enables left-right visualization \ 

644 on the same figure through 2D projections with \ 

645 :func:`~nilearn.plotting.plot_glass_brain`. 

646 

647 This visualization mode 

648 can be activated by setting ``display_mode='lr'``: 

649 

650 .. code-block:: python 

651 

652 from nilearn.datasets import load_mni152_template 

653 from nilearn.plotting import plot_glass_brain 

654 

655 img = load_mni152_template() 

656 # display is an instance of the LRProjector class 

657 display = plot_glass_brain(img, display_mode="lr") 

658 

659 Attributes 

660 ---------- 

661 axes : :obj:`dict` of :class:`~nilearn.plotting.displays.GlassBrainAxes` 

662 The axes used for plotting in each direction ('l', and 'r' here). 

663 

664 frame_axes : :class:`~matplotlib.axes.Axes` 

665 The axes framing the whole set of views. 

666 

667 """ 

668 

669 _cut_displayed = "lr" 

670 

671 

672class LProjector(OrthoProjector): 

673 """The ``LProjector`` class enables the visualization of left 2D \ 

674 projection with :func:`~nilearn.plotting.plot_glass_brain`. 

675 

676 This 

677 visualization mode can be activated by setting ``display_mode='l'``: 

678 

679 .. code-block:: python 

680 

681 from nilearn.datasets import load_mni152_template 

682 from nilearn.plotting import plot_glass_brain 

683 

684 img = load_mni152_template() 

685 # display is an instance of the LProjector class 

686 display = plot_glass_brain(img, display_mode="l") 

687 

688 Attributes 

689 ---------- 

690 axes : :obj:`dict` of :class:`~nilearn.plotting.displays.GlassBrainAxes` 

691 The axes used for plotting in each direction ('l' here). 

692 

693 frame_axes : :class:`~matplotlib.axes.Axes` 

694 The axes framing the whole set of views. 

695 

696 See Also 

697 -------- 

698 nilearn.plotting.displays.RProjector : right projection view 

699 

700 """ 

701 

702 _cut_displayed: ClassVar[str] = "l" 

703 _default_figsize: ClassVar[list[float]] = [2.6, 3.0] 

704 

705 

706class RProjector(OrthoProjector): 

707 """The ``RProjector`` class enables the visualization of right 2D \ 

708 projection with :func:`~nilearn.plotting.plot_glass_brain`. 

709 

710 This visualization mode can be activated by setting ``display_mode='r'``: 

711 

712 .. code-block:: python 

713 

714 from nilearn.datasets import load_mni152_template 

715 from nilearn.plotting import plot_glass_brain 

716 

717 img = load_mni152_template() 

718 # display is an instance of the RProjector class 

719 display = plot_glass_brain(img, display_mode="r") 

720 

721 Attributes 

722 ---------- 

723 axes : :obj:`dict` of :class:`~nilearn.plotting.displays.GlassBrainAxes` 

724 The axes used for plotting in each direction ('r' here). 

725 

726 frame_axes : :class:`~matplotlib.axes.Axes` 

727 The axes framing the whole set of views. 

728 

729 See Also 

730 -------- 

731 nilearn.plotting.displays.LProjector : left projection view 

732 

733 """ 

734 

735 _cut_displayed: ClassVar[str] = "r" 

736 _default_figsize: ClassVar[list[float]] = [2.6, 2.8] 

737 

738 

739PROJECTORS = { 

740 "ortho": OrthoProjector, 

741 "xz": XZProjector, 

742 "yz": YZProjector, 

743 "yx": YXProjector, 

744 "x": XProjector, 

745 "y": YProjector, 

746 "z": ZProjector, 

747 "lzry": LZRYProjector, 

748 "lyrz": LYRZProjector, 

749 "lyr": LYRProjector, 

750 "lzr": LZRProjector, 

751 "lr": LRProjector, 

752 "l": LProjector, 

753 "r": RProjector, 

754} 

755 

756 

757def get_projector(display_mode): 

758 """Retrieve a projector from a given display mode. 

759 

760 Parameters 

761 ---------- 

762 display_mode : {"ortho", "xz", "yz", "yx", "x", "y",\ 

763 "z", "lzry", "lyrz", "lyr", "lzr", "lr", "l", "r"} 

764 The desired display mode. 

765 

766 Returns 

767 ------- 

768 projector : :class:`~nilearn.plotting.displays.OrthoProjector`\ 

769 or instance of derived classes 

770 

771 The projector corresponding to the requested display mode: 

772 

773 - "ortho": Returns an 

774 :class:`~nilearn.plotting.displays.OrthoProjector`. 

775 - "xz": Returns a 

776 :class:`~nilearn.plotting.displays.XZProjector`. 

777 - "yz": Returns a 

778 :class:`~nilearn.plotting.displays.YZProjector`. 

779 - "yx": Returns a 

780 :class:`~nilearn.plotting.displays.YXProjector`. 

781 - "x": Returns a 

782 :class:`~nilearn.plotting.displays.XProjector`. 

783 - "y": Returns a 

784 :class:`~nilearn.plotting.displays.YProjector`. 

785 - "z": Returns a 

786 :class:`~nilearn.plotting.displays.ZProjector`. 

787 - "lzry": Returns a 

788 :class:`~nilearn.plotting.displays.LZRYProjector`. 

789 - "lyrz": Returns a 

790 :class:`~nilearn.plotting.displays.LYRZProjector`. 

791 - "lyr": Returns a 

792 :class:`~nilearn.plotting.displays.LYRProjector`. 

793 - "lzr": Returns a 

794 :class:`~nilearn.plotting.displays.LZRProjector`. 

795 - "lr": Returns a 

796 :class:`~nilearn.plotting.displays.LRProjector`. 

797 - "l": Returns a 

798 :class:`~nilearn.plotting.displays.LProjector`. 

799 - "z": Returns a 

800 :class:`~nilearn.plotting.displays.RProjector`. 

801 

802 """ 

803 return get_create_display_fun(display_mode, PROJECTORS)