code: def test_plot_carpet_with_atlas(img_4d_mni, img_atlas):
      """Test plot_carpet when using an atlas."""
      # Test atlas - labels
      # t_r is set explicitly for this test as well
      display = plot_carpet(
          img_4d_mni,
          mask_img=img_atlas["img"],
          t_r=2,
          detrend=False,
          title="TEST",
      )
  
      # Check the output
      # Two axes: 1 for colorbar and 1 for imshow
      assert len(display.axes) == 2
      # The y-axis label of the imshow should be 'voxels' since atlas labels are
      # unknown
      ax = display.axes[1]
      assert ax.get_ylabel() == "voxels"
  
      # Next two lines retrieve the numpy array from the plot
      ax = display.axes[0]
      colorbar = ax.images[0].get_array()
      assert len(np.unique(colorbar)) == len(img_atlas["labels"])
  
      # Save execution time and memory
      plt.close(display)
  
      # Test atlas + labels
      fig, ax = plt.subplots()
      display = plot_carpet(
          img_4d_mni,
          mask_img=img_atlas["img"],
          mask_labels=img_atlas["labels"],
          detrend=True,
          title="TEST",
          figure=fig,
          axes=ax,
      )
      # Check the output
      # Two axes: 1 for colorbar and 1 for imshow
      assert len(display.axes) == 2
      ax = display.axes[0]
  
      # The ytick labels of the colorbar should match the atlas labels
      yticklabels = ax.get_yticklabels()
      yticklabels = [yt.get_text() for yt in yticklabels]
      assert set(yticklabels) == set(img_atlas["labels"].keys())
  
      # Next two lines retrieve the numpy array from the plot
      ax = display.axes[0]
      colorbar = ax.images[0].get_array()
      assert len(np.unique(colorbar)) == len(img_atlas["labels"])
      plt.close(display)
  
file_path: nilearn/nilearn/plotting/tests/test_img_plotting/test_plot_carpet.py
imports: import warnings
  import matplotlib.pyplot
  import numpy
  import pytest
  from nilearn.plotting import plot_carpet
label_desc: Use image node_id 2 for calling a global function with example usage: test_plot_carpet_with_atlas(img_4d_mni, img_atlas) without return types