U
    f»{jÈÑ  ã                   @   sF  d Z ddlZddlZddlmZ ddlmZ ddlmZ ddl	Z	ddl
mZ ddlZddlmZ ddlmZmZmZmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZmZm Z m!Z! ddl"m#Z#m$Z$m%Z% ddl&m'Z'm(Z( ddl)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2 ddlm3Z3 ddl4m5Z5 ddl)m6Z6m7Z7m8Z8m9Z9m:Z:m;Z; dd„ Z<e+dLdd„ƒZ=dMdd„Z>dddddddd œd!d"„Z?e2dNd$d%„ƒZ@d&d'„ ZAe+dOd)d*„ƒZBd+d,„ ZCdPd-d.„ZDdQd0d1„ZEd2d3„ ZFdRd4d5„ZGd6d7„ ZHd8ZIdddd9dd:eIddd;dfdd<œd=d>„ZJdd?dd:eId@dAdBdf	dCdD„ZKdEdF„ ZLe2dSdHdI„ƒZMdTdJdK„ZNdS )Uz/Functions to make simple plots with M/EEG data.é    N)Úglob)Úcycle)Údefaultdicté   )ÚDEFAULTS)Ú_reorient_imageÚ_read_mri_infoÚ
_check_mriÚ_mri_orientation)Úcompute_rank)Úread_surface)ÚFIFF)Úmake_projector)Ú_DATA_CH_TYPES_SPLITÚ
pick_typesÚ	pick_infoÚpick_channels)Úread_source_spacesÚSourceSpacesÚ_ensure_src)Úapply_transÚ_frame_to_str)	ÚloggerÚverboseÚwarnÚ_check_optionÚget_subjects_dirÚ_mask_to_onsets_offsetsÚ_plÚ_on_missingÚfill_doc)Ú_picks_by_type)Úestimate_ringing_samplesé   )Útight_layoutÚ_get_color_listÚ_prepare_trellisÚplt_showÚ_figure_aggÚ_validate_typec           
         sØ   |dkrˆd }t ˆtˆd ˆd |ƒƒ‰~tˆdddd�}t|ƒ}‡fdd„ˆjD ƒ‰ ‡fd	d„ˆ D ƒ}ˆd ‰ttƒ‰| ¡ D ] \}}‡ ‡fd
d„|D ƒˆ|< q‚‡fdd„tD ƒ}ˆj	| d d …|f }	ˆ|	ˆ |fS )NZbadsÚch_namesÚnamesF© )Zmeg_combinedÚref_megÚexcludec                    s   g | ]}|ˆ d  kr|‘qS ©r*   r,   ©Ú.0Ún©Úinfor,   úK/var/www/html/bwave/python/venv/lib/python3.8/site-packages/mne/viz/misc.pyÚ
<listcomp>5   s      z#_index_info_cov.<locals>.<listcomp>c                    s   g | ]}ˆ j  |¡‘qS r,   ©r*   Úindexr0   )Úcovr,   r5   r6   6   s     c                    s&   g | ]}ˆ| ˆ krˆ   ˆ| ¡‘qS r,   ©r8   ©r1   Úc)r*   Úinfo_ch_namesr,   r5   r6   ;   s    ÿc                    sJ   g | ]B}t ˆ | ƒd krˆ | dtd |  td | td | |f‘qS )r   z%s covarianceÚtitlesÚunitsÚscalings)Úlenr   )r1   Úkey)Úidx_by_typer,   r5   r6   =   s   ú

ü)
r   r   r!   Údictr*   r   ÚlistÚitemsr   Údata)
r4   r9   r.   Z
picks_listZpicks_by_typeZch_idxÚch_typeÚselÚ	idx_namesÚCr,   )r*   r9   rC   r4   r=   r5   Ú_index_info_cov*   s0    ÿÿÿÿ
ûrL   r,   TFc           &         sœ  ddl m} ddlm}	 ddlm}
 ddlm} tˆ | |ƒ\‰ }}}~ ~g }|r¸t	 
ˆ d ¡}|D ]}d|d	< qbt||ƒ\}}}|dkr®t d
| ¡ t |t ||j¡¡}n
t d¡ t |¡rÖt || ¡  j¡}|jdt|ƒddt|ƒ dfd�\}}t|ƒD ]È\}\}}}}}t t || dd…|f ¡¡}|d|f j|| dd…|f d|	| |d�dd�}|d|f j|d� |�rddlm} ||d|f ƒ}|jdddd�}| d¡ |j ||dd� �q| !dddd d!d"¡ t"|d#� d}|�rŒ|jdt|ƒddt|ƒ dfd�\}}t|ƒD �]Z\}\}}}} }!|| dd…|f }"|
j#|"dd$�}#||"‡ fd%d&„|D ƒg g dƒ}"t$ˆ |ƒ}$|$ %¡ � g |$d< W 5 Q R X t&|"|$d'�}%d(|#|#dk  '¡  |#|#dk< t |#¡|  }#|d|f j(|#d)d*d+� |%|! }%|d|f j)|%d d,d-d.d/dd0� |d|f j*|%d |d|f  +¡ d d1|%f dd2d-d.d/d3� |d|f jd4| d5d6|dt|#ƒd gd7� �q$t"|d#� t,|ƒ ||fS )8a8  Plot Covariance data.

    Parameters
    ----------
    cov : instance of Covariance
        The covariance matrix.
    %(info_not_none)s
    exclude : list of str | str
        List of channels to exclude. If empty do not exclude any channel.
        If 'bads', exclude info['bads'].
    colorbar : bool
        Show colorbar or not.
    proj : bool
        Apply projections or not.
    show_svd : bool
        Plot also singular values of the noise covariance for each sensor
        type. We show square roots ie. standard deviations.
    show : bool
        Show figure if True.
    %(verbose)s

    Returns
    -------
    fig_cov : instance of matplotlib.figure.Figure
        The covariance plot.
    fig_svd : instance of matplotlib.figure.Figure | None
        The SVD spectra plot of the covariance.

    See Also
    --------
    mne.compute_rank

    Notes
    -----
    For each channel type, the rank is estimated using
    :func:`mne.compute_rank`.

    .. versionchanged:: 0.19
       Approximate ranks for each channel type are shown with red dashed lines.
    r   N)Ú	Normalize)Úlinalgr   )Ú
CovarianceÚprojsTZactivez5    Created an SSP operator (subspace dimension = %d)z:    The projection vectors do not apply to these channels.r#   Fgffffff@gš™™™™™@©ZsqueezeÚfigsizeÚnearest)ÚvminÚvmaxZRdBu_r)ÚinterpolationZnormÚcmap©Útitle)Úmake_axes_locatableÚrightz5.5%çš™™™™™©?)ÚsizeÚpadz%.0e)ÚcaxÚformatg{®Gáz¤?ç        g\�Âõ(\ï?g®Gázî?gš™™™™™É?g¤p=
×£Ð?©Úfig)Z
compute_uvc                    s   g | ]}ˆ d  | ‘qS r/   r,   )r1   Úiir3   r,   r5   r6   ©   s     zplot_cov.<locals>.<listcomp>r3   g»½×Ùß|Û=Úké   )ÚcolorÚzorderú--Úrç      à?é   )Úlsrg   Úalpharh   Úclip_onu   rank â‰ˆ %dÚtop)ÚhaÚvarg   rn   rh   u   Noise Ïƒ (%s)ÚlogzEigenvalue index)ÚylabelÚyscaleÚxlabelrY   Úxlim)-Úmatplotlib.pyplotÚpyplotZmatplotlib.colorsrM   ZscipyrN   r9   rO   rL   ÚcopyÚdeepcopyr   r   r4   ÚnpÚdotÚTZiscomplexobjÚsqrtÚconjÚrealÚsubplotsrA   Ú	enumerateÚmaxÚabsÚimshowÚsetZmpl_toolkits.axes_grid1rZ   Zappend_axesÚgridÚcolorbarÚsubplots_adjustr$   Zsvdr   Z_unlockr   ÚminÚplotZaxvlineÚtextZget_ylimr'   )&r9   r4   r.   r‰   ZprojZshow_svdÚshowr   ÚpltrM   rN   rO   rK   r*   rJ   rP   ÚpÚPZncompÚ_Zfig_covÚaxesre   ÚidxÚnameZvlimÚimrZ   Údividerr_   Zfig_svdÚunitÚscalingrB   Zthis_CÚsZ	this_infoZ	this_rankr,   r3   r5   Úplot_covH   s     +
ÿ

ÿ
  þ

ÿ
  ÿ

  ÿ$    þ þ

r›   c                 C   sì  ddl m} t| ƒdkr tdƒ‚| d }|dk	rF||jd k rFtdƒ‚|dk	rj||jd |j krjtdƒ‚|dkr||jd }|dkr”|jd |j }t |||j |j¡}	tt	t 
|¡ƒƒ}
t |
¡}g }| D ]*}| ¡ }| |||j ¡ | |j¡ qÎt |¡}|dk�r$t | ¡ |j¡d }g }tt|ƒd ƒD ]D}|| d }||d  d }||k�r8|
 |¡ | ||f¡ �q8t |	|
¡\}}|jdd	�}|j|||dd…|dd…f d
d� | ¡ }|j	dddd� dd„ |	D ƒ}dt|	ƒd  }tt|	ƒƒD ]}|| dk�r d||< �q | |	¡ | |¡ | |	d |	d ¡ | d¡ | |¡ | dd„ |D ƒ¡ |  |
d |
d ¡ |j!ddd� |�rž| "¡  t#|d� |D ]2\}}|j$||	d |	d  || |	d dd� �q¬t%|ƒ |S )a-  Plot source power in time-freqency grid.

    Parameters
    ----------
    stcs : list of SourceEstimate
        Source power for consecutive time windows, one SourceEstimate object
        should be provided for each frequency bin.
    freq_bins : list of tuples of float
        Start and end points of frequency bins of interest.
    tmin : float
        Minimum time instant to show.
    tmax : float
        Maximum time instant to show.
    source_index : int | None
        Index of source for which the spectrogram will be plotted. If None,
        the source with the largest activation will be selected.
    colorbar : bool
        If true, a colorbar will be added to the plot.
    show : bool
        Show figure if True.

    Returns
    -------
    fig : instance of Figure
        The figure.
    r   Nz)cannot plot spectrogram if len(stcs) == 0zAtmin cannot be smaller than the first time point provided in stcséÿÿÿÿzgtmax cannot be larger than the sum of the last time point and the time step, which are provided in stcsr#   )é	   é   )rR   ZReds)rW   zSource powerúTime (s)úFrequency (Hz))rY   rv   rt   c                 S   s   g | ]}t t |d ¡ƒ‘qS ©r   )Ústrr|   Úround©r1   Útr,   r,   r5   r6     s     z+plot_source_spectrogram.<locals>.<listcomp>é
   Ú rs   c                 S   s   g | ]}t  |d ¡‘qS r¡   )r|   r£   )r1   Úfreqr,   r,   r5   r6   #  s     Tú-)rm   rb   z#666666©rg   )&rx   ry   rA   Ú
ValueErrorÚtimesZtstepr|   ÚarangeÚsortedr‡   Zravelrz   r{   ÚcropÚappendrG   ÚarrayZunravel_indexZargmaxÚshapeÚrangeÚremoveZmeshgridÚfigureZpcolorÚgcaÚ
set_xticksZset_xticklabelsrw   ru   Ú
set_yticksÚset_yticklabelsÚylimrˆ   r‰   r$   Zbarhr'   )ZstcsZ	freq_binsZtminZtmaxZsource_indexr‰   rŽ   r�   ZstcZtime_boundsZfreq_boundsZ
freq_ticksZsource_powerZ
gap_boundsÚiÚlower_boundÚupper_boundZ	time_gridZ	freq_gridrc   ÚaxZtime_tick_labelsZn_skipr,   r,   r5   Úplot_source_spectrogramÃ   s„    




ÿÿ

ÿ




ÿ ÿ
r¿   Úcoronali   )ÚorientationÚslicesrŽ   Úshow_indicesÚshow_orientationÚwidthÚslices_as_subplotsc        
   7      C   sÜ  ddl m}
 ddlm} t|ttfdƒ t|tƒrBtd|ddd� td|d	ƒ t	| d
dd�\}}}}}}t
|ƒ\}}tj |¡}t|ƒ\}}}|j| }|dkrÌt tjd|d dd�¡ t¡}|dd… }t |¡ ¡ }||dk   |7  < t t |¡|¡�rD|jdk�sD|jdk �sD|d dk �sD|d |k�sD|jjdk�rXtd|d |f ƒ‚tƒ }|D ]D\}}tƒ }t|ƒ\|d< |d< t ||d ƒ|d< | !||f¡ �qbtƒ }|dk	�r6t"|dd� |d d t#j$k�ròtdt%|d d  › �ƒ‚|D ]0}|d |d  t¡ }| !t ||d ƒ¡ �qötj&|dd�}|	�rrd}t't(|ƒ|ƒ\}}}}| )d¡ | *¡ }t(|ƒ} n0d }} d}|| }!|!|!|j|  |j|  f}"t &tj+ g|dd… t ,|¡d  tj+gg¡}#t-dƒgd }$td d!d"d#�}%|%d$|  |%d$|   }&}'|j.ddd%d&�g}(g })t/t0||#dd… |#dd… ƒƒD �]f\}*\}+},}-|	�r^||* }.n&t1|"|dd'�}|j2ddddgd(dd)�}.|+|$|< |t3|$ƒ j4}/|.j5|/|
j6j7d*d+� |. 8d(¡ |. 9d,¡ |. :d-¡ |D ]|\}}t;j<dd.��` t; =d/¡ |.j>|d dd…|f |d dd…|f |d |d dd…|f |+g|d0dd1� W 5 Q R X �qÐt(|ƒ�r¦|dd…|f |,k|dd…|f |-k @ }0|.j?||0|f ||0|f d2d3dd4d5� |�rÖ|.j@|/jd d6 d7 d7t|+ƒd8d9d:d;d<� td=d>|(d?d(d@dAdB�}1|dCk}2|�r|*| dk�s|2�r8|.j@d|/jd d |&d fdDd;dEœ|1—Ž |*| |d k�s^|*| d k�s^|2�r’|.j@|/jd d |/jd d |&d fdDdFdEœ|1—Ž |*| | k�s¦|2�rÐ|.j@|/jd d d|'d fdDd:dGœ|1—Ž |*|k �sê|dk�sê|2�r|.j@|/jd d |/jd d |'d fdDdHdGœ|1—Ž |	�s>tA B¡ �P}3|jC|3dIdJd|dK� |jD E¡ \}4}5|
 F|¡ |3 Gd¡ tjH|3 I¡ tjJdL�}6W 5 Q R X |6 Kt|5ƒt|4ƒdf¡}|) !|¡ �q>|	�rÔ|jLdMdMd0d0dMdMdN� tM||dO� |S |)S dS )PaŒ  Plot BEM contours on anatomical MRI slices.

    Parameters
    ----------
    slices_as_subplots : bool
        Whether to add all slices as subplots to a single figure, or to
        create a new figure for each slice. If ``False``, return NumPy
        arrays instead of Matplotlib figures.

    Returns
    -------
    matplotlib.figure.Figure | list of array
        The plotted slices.
    r   N)ÚpatheffectsrÄ   )Úalwayszwhen str)ÚextrarÁ   )rÀ   ZaxialZsagittalÚmmT)r?   Z
return_imgr#   é   )ÚstartÚstopÚnumrœ   Úiuz{slices must be a sorted 1D array of int with unique elements, at least one element, and no elements greater than %d, got %sZrrZtrisz or NoneZcoord_framez-Source space must be in MRI coordinates, got Zinuseg     @�@)Úaxisrl   re   é`   ç       @rf   ZLRZPAZIS)ÚRÚAÚSZRASg      è?)Ú	linewidthÚ
foregroundrn   )rR   ÚdpiÚ	facecolorF)Zframe_onrÙ   Úlower)rW   ÚoriginÚoffÚequal©ÚrecordÚignoreç      ð?)ZlevelsÚcolorsZ
linewidthsrh   Ú.z#FF00FFr   )Úmarkerrg   rš   rh   é   rk   Úwzx-smallÚbottomÚleft)rg   Úfontsizerr   rq   z#66CCEEZmediumZ	monospaceé   Úbold)rg   ré   Úpath_effectsÚfamilyro   rh   ÚweightrÈ   Úcenter)rr   rq   r[   )rq   rr   rp   ÚrawZtight)r`   Zbbox_inchesZ
pad_inchesrØ   )Údtypera   )rè   rç   r[   rp   ZwspaceÚhspacerb   )Nrx   ry   Z
matplotlibrÇ   r)   Úboolr¢   Ú
isinstancer   r   r   r|   rN   Úinvr
   r²   r£   ÚlinspaceZastypeÚintZ
atleast_1drz   Zarray_equalÚsortÚndimr]   rñ   Úkindr«   rE   rD   r   r   r°   r   r   ZFIFFV_COORD_MRIr   Zconcatenater&   rA   Zset_facecolorZget_dpiÚinfÚdiffÚsliceZ
withStrokerƒ   Úzipr(   Zadd_axesÚtupler~   r†   ÚcmÚgrayZset_autoscale_onrÐ   Z
set_aspectÚwarningsÚcatch_warningsÚsimplefilterZ
tricontourZscatterr�   ÚioÚBytesIOZsavefigÚcanvasZget_width_heightÚcloseÚseekZ
frombufferÚgetvalueZuint8ZreshaperŠ   r'   )7Ú	mri_fnameÚsurfacesÚsrcrÁ   rÂ   rŽ   rÃ   rÄ   rÅ   rÆ   r�   rÇ   r’   ÚnimrG   Zrasvox_mri_tZmri_rasvox_trÐ   ÚxÚyZn_slicesZsurfsÚ	file_namerg   ÚsurfÚsourcesÚsrc_ZpointsZn_colrc   ZaxsrØ   Zn_axesræ   rR   ZboundsZslicerZ
ori_labelsZxlabelsZylabelsrì   ÚfigsZaiÚslrÚ   Úupperr¾   ZdatZin_sliceÚkwargsrÈ   ZbuffZw_Zh_Z	fig_arrayr,   r,   r5   Ú_plot_mri_contours4  sj   
ÿ  ÿ
ýÿú	 ÿ
ÿ
ÿ
þ
þ
ÿ

 ÿÿÿÿ




(   ý
(   ÿ   ÿ     þ ÿÿ&$ ÿÿ ÿÿ$ ÿÿ
   þ

ÿr  úT1.mgzc
                 C   sV  t |dd�}t|| |ƒ}
t || d¡}t |¡s@td|› d�ƒ‚t|ƒ}|dk	r²t|tƒr`|f}|D ]L}dD ]B}t || d|d	 | ¡}t 	|¡r¢| 
|d
f¡ qltd| ƒ‚qlqdt|tƒrüt 	|¡sòt || d|¡}t 	|¡ræ|}ntd| ƒ‚t|ƒ}n&|dk	�r"t|tƒ�s"tdt|ƒ ƒ‚t|ƒdk�r8tdƒ‚t|
|||||||	dd�	}|S )aª	  Plot BEM contours on anatomical MRI slices.

    Parameters
    ----------
    %(subject)s
    %(subjects_dir)s
    orientation : str
        'coronal' or 'axial' or 'sagittal'.
    slices : list of int | None
        The indices of the MRI slices to plot. If ``None``, automatically
        pick 12 equally-spaced slices.
    brain_surfaces : None | str | list of str
        One or more brain surface to plot (optional). Entries should correspond
        to files in the subject's ``surf`` directory (e.g. ``"white"``).
    src : None | SourceSpaces | str
        SourceSpaces instance or path to a source space to plot individual
        sources as scatter-plot. Sources will be shown on exactly one slice
        (whichever slice is closest to each source in the given orientation
        plane). Path can be absolute or relative to the subject's ``bem``
        folder.

        .. versionchanged:: 0.20
           All sources are shown on the nearest slice rather than some
           being omitted.
    show : bool
        Show figure if True.
    show_indices : bool
        Show slice indices if True.

        .. versionadded:: 0.20
    mri : str
        The name of the MRI to use. Can be a standard FreeSurfer MRI such as
        ``'T1.mgz'``, or a full path to a custom MRI file.

        .. versionadded:: 0.21
    show_orientation : bool | str
        Show the orientation (L/R, P/A, I/S) of the data slices.
        True (default) will only show it on the outside most edges of the
        figure, False will never show labels, and "always" will label each
        plot.

        .. versionadded:: 0.21
        .. versionchanged:: 0.24
           Added support for "always".

    Returns
    -------
    fig : instance of matplotlib.figure.Figure
        The figure.

    See Also
    --------
    mne.viz.plot_alignment

    Notes
    -----
    Images are plotted in MRI voxel coordinates.

    If ``src`` is not None, for a given slice index, all source points are
    shown that are halfway between the previous slice and the given slice,
    and halfway between the given slice and the next slice.
    For large slice decimations, this can
    make some source points appear outside the BEM contour, which is shown
    for the given slice index. For example, in the case where the single
    midpoint slice is used ``slices=[128]``, all source points will be shown
    on top of the midpoint MRI slice with the BEM boundary drawn for that
    slice.
    T)Zraise_errorZbemzSubject bem directory "z" does not existN)ZlhZrhr  rã   z#00DD00zSurface %s does not exist.z%s does not existz:src needs to be None, str or SourceSpaces instance, not %sr   ziNo surface files found. Surface files must end with inner_skull.surf, outer_skull.surf or outer_skin.surf)	r  r  r  rÁ   rÂ   rŽ   rÃ   rÄ   rÆ   )r   r	   ÚopÚjoinÚisdirÚIOErrorÚ_get_bem_plotting_surfacesrô   r¢   Úexistsr°   r   r   Ú	TypeErrorÚreprrA   r  )ÚsubjectZsubjects_dirrÁ   rÂ   Zbrain_surfacesr  rŽ   rÃ   ZmrirÄ   r  Úbem_pathr  Ú	surf_nameZhemiÚ
surf_fnamer  rc   r,   r,   r5   Úplot_bemì  sT    H



ÿ




ÿ     ür'  c                 C   sZ   g }dD ]L\}}t t | |d ¡ƒ}t|ƒdkr|d }t d| ¡ | ||f¡ q|S )N))z*inner_skullz#FF0000)z*outer_skullz#FFFF00)z*outer_skinz#FFAA80z.surfr   zUsing surface: %s)r   r  r  rA   r   r4   r°   )r$  r  r%  rg   r&  r,   r,   r5   r  d  s    r  Úraisec
           $      C   s¬  |dkrd}d}
nd}
t  | ¡} t| ƒdkr4tdƒ‚t  | dd…df ¡}|dk	�r*dd	„ | ¡ D ƒ}tt| ¡ d
d„ d�Ž \}}t  t|ƒt	¡}t
|ƒD ],\}}||krš|› d�}t||ƒ d||< qšdd„ t||ƒD ƒ}dd„ t||ƒD ƒ}t|ƒdk�rtdƒ‚|D ]}||k�r
td| ƒ �q
n|}t|||ƒ}ddlm} d}|dk�r\| ¡ }|�rf|n| ¡ }t  |¡}t  |¡}t  |¡}| t  | dd…df |¡df  ¡ | | }tƒ tƒ  }}t
|ƒD ]Ø\}}| dd…df |k}| ¡ }|dk�r �qÎt  ||�r|d n| |df d ¡}|dk	�rBd|| |f } n
d|f } | | ¡ i }!||k�rp|| |!d< | |j| |df | | |dfddi|!—Žd ¡ �qÎ|�râ| d|jd ¡ | dt  |j¡ ¡ |  |¡ n| |d |d g¡ |j!|
dd|gd� | "d¡ |dk	�r$|n| #¡ }|ddd… |ddd…  }}| $¡ }"|dk	�r`dnd}#| %|"j&|"j'|"j(|# |"j)g¡ |j*||d d!d"d#� |j+ ,¡  t-|ƒ |S )$a   Plot :term:`events` to get a visual display of the paradigm.

    Parameters
    ----------
    %(events)s
    sfreq : float | None
        The sample frequency. If None, data will be displayed in samples (not
        seconds).
    first_samp : int
        The index of the first sample. Recordings made on Neuromag systems
        number samples relative to the system start (not relative to the
        beginning of the recording). In such cases the ``raw.first_samp``
        attribute can be passed here. Default is 0.
    color : dict | None
        Dictionary of event_id integers as keys and colors as values. If None,
        colors are automatically drawn from a default list (cycled through if
        number of events longer than list of default colors). Color can be any
        valid :doc:`matplotlib color <matplotlib:tutorials/colors/colors>`.
    event_id : dict | None
        Dictionary of event labels (e.g. 'aud_l') as keys and their associated
        event_id values. Labels are used to plot a legend. If None, no legend
        is drawn.
    axes : instance of Axes
       The subplot handle.
    equal_spacing : bool
        Use equal spacing between events in y-axis.
    show : bool
        Show figure if True.
    %(on_missing_events)s
    %(verbose)s

    Returns
    -------
    fig : matplotlib.figure.Figure
        The figure object containing the plot.

    Notes
    -----
    .. versionadded:: 0.9.0
    Nrá   ZSamplesrŸ   r   z'No events in events array, cannot plot.r   c                 S   s   i | ]\}}||“qS r,   r,   )r1   re   Úvr,   r,   r5   Ú
<dictcomp>«  s      zplot_events.<locals>.<dictcomp>c                 S   s   | d S )Nr#   r,   )r  r,   r,   r5   Ú<lambda>­  ó    zplot_events.<locals>.<lambda>)rB   z( from event_id is not present in events.Fc                 S   s   g | ]\}}|r|‘qS r,   r,   )r1   Zcondre   r,   r,   r5   r6   µ  s      zplot_events.<locals>.<listcomp>c                 S   s   g | ]\}}|r|‘qS r,   r,   )r1   Zid_re   r,   r,   r5   r6   ¶  s      zNo usable event IDs foundz.event %s missing from event_id will be ignoredr#   z%s (%s)zN=%drg   rã   ro   zEvent id)rv   rt   rw   Trœ   çš™™™™™é?gÍÌÌÌÌÌì?zcenter left)r#   rk   Zsmall)ÚlocZbbox_to_anchorré   ).r|   ZasarrayrA   r«   ÚuniquerF   rþ   r®   Úonesró   rƒ   r   ÚRuntimeErrorr   Ú_handle_event_colorsrx   ry   rµ   r¶   r±   r‹   r„   Zin1drE   ÚsumÚfullr°   rŒ   Zset_ylimr]   r¸   r­   r¹   r‡   rˆ   ZgcfZget_positionZset_positionZx0Zy0rÅ   ÚheightÚlegendr  Zdrawr'   )$ÚeventsÚsfreqZ
first_samprg   Úevent_idr“   Zequal_spacingrŽ   Z
on_missingr   rv   Úunique_eventsZevent_id_revÚ
conditionsZunique_events_idZkeeprd   Z
this_eventÚmsgr�   rc   r¾   Z	min_eventZ	max_eventZmax_xZhandlesÚlabelsr”   ZevZev_maskÚcountr  Zevent_labelr  ÚboxÚfactorr,   r,   r5   Úplot_eventsq  s®    ,


ÿ



ÿ



"ÿÿ
&



 ÿÿÿÿÿ
ÿ
rA  c                 C   sP   | j jjd }d}| ¡ D ]$\}}|ƒ }|jjdkr: q@qd}q|dk	sLt‚|S )zGet our press callback.Zbutton_press_eventNÚpartial)r  Ú	callbacksrF   Ú	__class__Ú__name__ÚAssertionError)rc   rC  ÚfuncrB   Úvalr,   r,   r5   Ú_get_presserü  s    rI  c           	      C   s¾   ddl m} |dkrttƒ ƒ}| dd¡\}}tjtj g}t| |ƒD ]R\}}|j|j	|j
d |dd� t|d |j	d ƒ|d< t|d |j	d ƒ|d< qF|j|dd	d
� |rº|jdd� |S )aå  Plot the amplitude traces of a set of dipoles.

    Parameters
    ----------
    dipoles : list of instance of Dipole
        The dipoles whose amplitudes should be shown.
    colors : list of color | None
        Color to plot with each dipole. If None default colors are used.
    show : bool
        Show figure if True.

    Returns
    -------
    fig : matplotlib.figure.Figure
        The figure object containing the plot.

    Notes
    -----
    .. versionadded:: 0.9.0
    r   Nr#   g    eÍÍAg      ø?)rg   rÖ   rœ   rŸ   zAmplitude (nAm))rw   rv   rt   F)r   )rx   ry   r   r%   r‚   r|   rû   rþ   rŒ   r¬   Z	amplituder‹   r„   r‡   rŽ   )	Zdipolesrâ   rŽ   r�   rc   r¾   rw   Zdiprg   r,   r,   r5   Úplot_dipole_amplitudes
  s    
rJ  ©rp   r[   c                 C   sT   t | tttjfƒs| gn| } | D ].}|r4|jdd� |D ]}|j|  d¡ q8q dS )zõAdjust some properties of axes.

    Parameters
    ----------
    axes : list
        List of axes to process.
    remove_spines : list of str
        Which axis spines to remove.
    grid : bool
        Turn grid on (True) or off (False).
    r   )rh   FN)rô   rE   rÿ   r|   Úndarrayrˆ   ZspinesZset_visible)r“   Zremove_spinesrˆ   r¾   rB   r,   r,   r5   Úadjust_axes.  s    rM  c              	   C   sÚ   |dkrdS t  | ¡} tƒ }| d d| d  krBt  dddg¡}nt  dd¡}ttt  t  | d ¡¡ƒtt  t  | d ¡¡ƒd ƒD ]}||d	|   ¡ 7 }q„t  |¡}||| d k|| d k@  }d
d„ |D ƒ}||fS )z/Create approximately spaced ticks between lims.Úlinear)NNr#   é   r   r   rl   é   r¦   c                 S   s    g | ]}|d k rdnd| ‘qS )r#   z%gz%dr,   r¤   r,   r,   r5   r6   Q  s     z!_filter_ticks.<locals>.<listcomp>)	r|   r±   rE   r­   r³   r÷   ÚfloorÚlog10Útolist)ZlimsÚfscaleZticksÚbaseÚexpZ
ticklabelsr,   r,   r5   Ú_filter_ticksB  s    
ÿ
rW  c                 C   s´   | dkrn|dkr*|dkrdnd|d g} nD|dkr>|d g} n"|d dkrR|d n
d|d  g} | |d	 g7 } |dkr”| d dkr°t d
| d  ƒ‚n| d dk r°t d| d  ƒ‚| S )z Get reasonable frequency limits.Nrs   çš™™™™™¹?ra   rÒ   rN  r   r#   rœ   z flim[0] must be positive, got %sz$flim[0] must be non-negative, got %s)r«   )ÚflimrT  r¨   r8  r,   r,   r5   Ú	_get_flimU  s    "rZ  c                 C   s$   t | tƒr| dkr td| f ƒ‚dS )zCheck for valid fscale.)rs   rN  z(fscale must be "log" or "linear", got %sN)rô   r¢   r«   )rT  r,   r,   r5   Ú_check_fscaleh  s    ÿr[  )i°ÿÿÿr¦   z#1f77b4rs   )ÚtimeÚ	magnitudeÚdelay)Údlimc          ,   
   C   sþ  ddl m}m}m}m}m}m} ddlm} t	|ƒ}t
d|ddgƒ t|tƒrT|g}t|ƒD ]\}}t
d| |dƒ q\t||||ƒ}|dkr°t t |d ¡t |d	 ¡d
¡}nt |d |d	 d
¡}t||ƒ\}}||dtj   }t| tƒ�r*d| k�rt t|ƒtj¡}t t|ƒ¡}| d D ]Š}||dd… |dd… |ƒd	 }||9 }|
�rd|| ¡ 9 }nHtjdd��6 t d¡ |||dd… |dd… f|ƒd	 7 }W 5 Q R X �q$t| d ƒ}t |¡}d	|d< |
�rt ||d	 dfgd¡}|} |t|ƒd	 d 7 }n|} | | d |ƒ} nò|| d | d |ƒd	 }|
�rD|| ¡ 9 }tjdd��T t d¡ || d | d f|ƒd	 }|
�r ||| d  ¡ | d  ¡ |ƒd	 7 }W 5 Q R X t| d | d fƒ}t |¡}d	|d< |
�rôt ||d	 dfgd¡}|} n|} | | d | d |ƒ} |dk�rd}|
�r�|d7 }nf|| |d�d	 }tjdd��$ t d¡ || dgf|ƒd	 }W 5 Q R X |dk�r~dn|}|
�r�|d7 }d}!|dk�r²|  t|ƒd	¡\}!}t||j!ƒ�rÈ|g}nt|tj"ƒ�rÞt#|ƒ}|!dk�rô|d  $¡ }!t|ƒt|ƒk�rt%dt|ƒt|ƒf ƒ‚t &t| ƒ¡}"|dk�rRt '|"¡ (¡ d }| |g}|
�r�t| ƒd	 d }#|"|#8 }"|"d |"d  k�sˆt)‚||#8 }|"| }"|| }|| dtj  }$t*|dk�rÂdnd	ddƒ}%dt t +|| ¡  j,d¡¡ }&d|k�rDt -d d!„ |D ƒ¡d d }'||' j.|"| |d"� ||' j/|"ddg d#d$|d%� d&|k�rt -d'd!„ |D ƒ¡d d }(||( j.|$|% |&|% |dd(d)� |dk	�r´|dk	�r´t0||||( |d*d+� ||( j/d,d-|d.� |dk	�rò||( j/|d/� ||( j/|d0� ||( j/||d1d2d3� d4|k�rät -d5d!„ |D ƒ¡d d })||) j.|$|% ||% |dd(d)� t1t2|&d6kƒŽ D ].\}*}+||) j3|$|* |$|+d	  d7d8d9d:� �q^||) j/|d;d1|d<� |dk	�rÎ||) j/|d/� ||) j/|d0� ||) j/||d1d=d3� t4|ƒ t5ƒ  t6|	ƒ |!S )>aÜ	  Plot properties of a filter.

    Parameters
    ----------
    h : dict or ndarray
        An IIR dict or 1D ndarray of coefficients (for FIR filter).
    sfreq : float
        Sample rate of the data (Hz).
    freq : array-like or None
        The ideal response frequencies to plot (must be in ascending order).
        If None (default), do not plot the ideal response.
    gain : array-like or None
        The ideal response gains to plot.
        If None (default), do not plot the ideal response.
    title : str | None
        The title to use. If None (default), determine the title based
        on the type of the system.
    color : color object
        The color to use (default '#1f77b4').
    flim : tuple or None
        If not None, the x-axis frequency limits (Hz) to use.
        If None, freq will be used. If None (default) and freq is None,
        ``(0.1, sfreq / 2.)`` will be used.
    fscale : str
        Frequency scaling to use, can be "log" (default) or "linear".
    alim : tuple
        The y-axis amplitude limits (dB) to use (default: (-60, 10)).
    show : bool
        Show figure if True (default).
    compensate : bool
        If True, compensate for the filter delay (phase will not be shown).

        - For linear-phase FIR filters, this visualizes the filter coefficients
          assuming that the output will be shifted by ``N // 2``.
        - For IIR filters, this changes the filter coefficient display
          by filtering backward and forward, and the frequency response
          by squaring it.

        .. versionadded:: 0.18
    plot : list | tuple | str
        A list of the requested plots from ``time``, ``magnitude`` and
        ``delay``. Default is to plot all three filter properties
        ('time', 'magnitude', 'delay').

        .. versionadded:: 0.21.0
    axes : instance of Axes | list | None
        The axes to plot to. If list, the list must be a list of Axes of
        the same length as the number of requested plot types. If instance of
        Axes, there must be only one filter property plotted.
        Defaults to ``None``.

        .. versionadded:: 0.21.0
    dlim : None | tuple
        The y-axis delay limits (sec) to use (default:
        ``(-tmax / 2., tmax / 2.)``).

        .. versionadded:: 1.1.0

    Returns
    -------
    fig : matplotlib.figure.Figure
        The figure containing the plots.

    See Also
    --------
    mne.filter.create_filter
    plot_ideal_filter

    Notes
    -----
    .. versionadded:: 0.14
    r   )ÚfreqzÚgroup_delayÚlfilterÚfiltfiltÚsosfiltÚsosfiltfiltNrT  rs   rN  zplot[%d])r]  r^  r\  r#   iè  r   Úsosrf   TrÞ   rà   ZconstantÚbÚazSOS (IIR) filterz (forward-backward))ZworNrá   z
FIR filterz (delay-compensated)zRLength of axes (%d) must be the same as number of requested filter properties (%d)rÒ   rœ   r¦   g#B’¡œÇ;r\  c                 S   s   g | ]}|d k‘qS )r\  r,   ©r1   r�   r,   r,   r5   r6   &  s     zplot_filter.<locals>.<listcomp>rª   rŸ   Z	Amplitude)rw   rv   rt   rY   r]  c                 S   s   g | ]}|d k‘qS )r]  r,   ri  r,   r,   r5   r6   ,  s     rl   )rg   rÖ   rh   F)rT  rŽ   zMagnitude (dB)r§   )rt   rv   Úxscale©Úxticks©Úxticklabelsr    úAmplitude (dB))rw   rº   rv   rt   r^  c                 S   s   g | ]}|d k‘qS )r^  r,   ri  r,   r,   r5   r6   :  s     g33333óCÀre   r\   rê   )rÙ   rn   rh   zGroup delay (s))rw   rt   rv   rj  z	Delay (s))7Zscipy.signalr`  ra  rb  rc  rd  re  rx   ry   Úfloatr   rô   r¢   rƒ   rZ  r|   ZlogspacerR  rö   rW  ÚpirD   r0  rA   Z
complex128Zzerosr€   r  r  r  r"   r^   r‚   ZAxesrL  rE   Ú
get_figurer«   r­   r…   r„   rF  rý   Úmaximumr�   ÚwhererŒ   r‡   Úplot_ideal_filterrþ   r   ÚaxvspanrM  r$   r'   ),Úhr8  r¨   ÚgainrY   rg   rY  rT  ÚalimrŽ   Z
compensaterŒ   r“   r_  r`  ra  rb  rc  rd  re  r�   Úxir  Úomegarl  rn  ÚHÚgdÚsectionZthis_Hr2   ÚdeltarG  rc   r¥   Zn_shiftÚfr  ÚmagZax_time_idxZ
ax_mag_idxZax_delay_idxrÌ   rÍ   r,   r,   r5   Úplot_filterr  s   L 
$
 
4

.





þ

 
 ÿ
 ÿ ÿ
ÿ
 ÿ þ
þ
ÿr‚  r§   rj   rk   ri   c              	   C   s@  ddl m} tƒ tƒ  }}| d dkr8td| d f ƒ‚t | ¡} td|ddgƒ |dkr„|dkrnd| d  nt|d | d ƒ| d< t||| ƒ}tƒ }t	t
| ƒƒD ]°}|t
| ƒd k �r6|| ||d  k�r6|| | | |d  gg7 }|tj| | | |d  d	d
d� ¡ 7 }|tj|| ||d  d	d
d� ¡ 7 }q¢| | | ¡ | || ¡ q¢dt t |d|d d  ¡¡ }|dk�rŽ| d¡d }|D ]}|j||ddœŽ �q’|j||||	dddd� t||ƒ\}}|j|dd|d� |dk	�r|j|d� |j|d� |j|d� |�r$|j|d� t|ƒ tƒ  t|
ƒ |jS )a{  Plot an ideal filter response.

    Parameters
    ----------
    freq : array-like
        The ideal response frequencies to plot (must be in ascending order).
    gain : array-like or None
        The ideal response gains to plot.
    axes : instance of Axes | None
        The subplot handle. With None (default), axes are created.
    title : str
        The title to use, (default: '').
    flim : tuple or None
        If not None, the x-axis frequency limits (Hz) to use.
        If None (default), freq used.
    fscale : str
        Frequency scaling to use, can be "log" (default) or "linear".
    alim : tuple
        If not None (default), the y-axis limits (dB) to use.
    color : color object
        The color to use (default: 'r').
    alpha : float
        The alpha to use (default: 0.5).
    linestyle : str
        The line style to use (default: '--').
    show : bool
        Show figure if True (default).

    Returns
    -------
    fig : instance of matplotlib.figure.Figure
        The figure.

    See Also
    --------
    plot_filter

    Notes
    -----
    .. versionadded:: 0.14

    Examples
    --------
    Plot a simple ideal band-pass filter::

        >>> from mne.viz import plot_ideal_filter
        >>> freq = [0, 1, 40, 50]
        >>> gain = [0, 1, 1, 0]
        >>> plot_ideal_filter(freq, gain, flim=(0.1, 100))  #doctest: +SKIP
        <...Figure...>
    r   NzHfreq should start with DC (zero) and end with Nyquist, but got %s for DCrT  rs   rN  rX  r#   rO  F)Zendpointr¦   g      $@)rg   rn   rk   rl   rf   )rg   Ú	linestylern   rÖ   rh   r    ro  )rº   rv   rt   rj  rk  rm  )rw   rX   )rx   ry   rE   r«   r|   r±   r   r‹   rZ  r³   rA   rö   rS  r°   rR  rs  r‚   rv  rŒ   rW  r‡   rM  r$   r'   rµ   )r¨   rx  r“   rY   rY  rT  ry  rg   rn   rƒ  rŽ   r�   Zmy_freqZmy_gainZtransitionsrd   Z
transitionrl  rn  r,   r,   r5   ru  Q  s\    6ÿ
*(ÿÿ"
 ÿ
ÿ
ru  c           	      C   sÞ   t tt|ƒttƒ ƒƒƒ}| dkr<t|ƒttƒ ƒkrÚtdƒ nžt ƒ }|  ¡ D ]@\}}||krd|||< qJ||krz|||| < qJtdt|ƒ ƒ qJtt	|ƒt	|ƒ ƒ}t|ƒrÐd 
dd„ |D ƒ¡}tdt|ƒ|f ƒ | |¡ |S )zDCreate event-integer-to-color mapping, assigning defaults as needed.NzSMore events than default colors available. You should pass a list of unique colors.zJEvent ID %s is in the color dict but is not present in events or event_id.ú, c                 s   s   | ]}t |ƒV  qd S )N)r¢   )r1   Úer,   r,   r5   Ú	<genexpr>È  s     z'_handle_event_colors.<locals>.<genexpr>zCColor was not assigned for event%s %s. Default colors will be used.)rD   rþ   r®   r   r%   rA   r   rF   r¢   r‡   r  r   Úupdate)	Z
color_dictr:  r9  Zdefault_colorsZcustom_colorsrB   rg   Z
unassignedZunassigned_strr,   r,   r5   r2  ³  s*    

ÿ
ÿ
r2  Úcsdc           %   	      sŒ  ddl m} |dkrtdƒ‚|dk	rØ|d ‰t|dddg d�}t|d	ddg d�}	t|d
ddg d�}
‡ ‡fdd„|D ƒ}‡ ‡fdd„|	D ƒ}‡ ‡fdd„|
D ƒ}|||g}dddg}|dkrÖtdddd�}tdddd�}n@t tˆ jƒ¡g}|dk�rdg}tƒ }tƒ }n|dk�rdg}tˆ j	ƒ}|dk�r@t
t t |¡¡ƒ}t
t |t|ƒ ¡ƒ}g }t||dd	d
gƒD �]\}}}t|ƒdk�rŠ�ql|j||dd| d d | fd!�\}}g }ttˆ j	ƒƒD ]–}ˆ j|d"�| dd…|f }|dk�rt |¡| |d¡ }nH|dk�rLt |¡j}t |¡d |tjdd…f  |dd…tjf  }| |¡ �qÂt |¡}ttˆ j	|ƒƒD ]€\}\}} |||  ||  }!|!j| d#|d|d$�}"|! g ¡ |! g ¡ ˆ j�rä|! d%t |¡t |¡f ¡ n|! d&| ¡ �qt|  |¡ |j!d'd(� |�rr|j"|"d)d„ |D ƒd*�}#|dk�r^d+}$||k�rR|$d,||  7 }$|# #|$¡ n|dk�rr|# #d¡ | |¡ �qlt$|ƒ |S )-aÉ  Plot CSD matrices.

    A sub-plot is created for each frequency. If an info object is passed to
    the function, different channel types are plotted in different figures.

    Parameters
    ----------
    csd : instance of CrossSpectralDensity
        The CSD matrix to plot.
    %(info)s
        Used to split the figure by channel-type, if provided.
        By default, the CSD matrix is plotted as a whole.
    mode : 'csd' | 'coh'
        Whether to plot the cross-spectral density ('csd', the default), or
        the coherence ('coh') between the channels.
    colorbar : bool
        Whether to show a colorbar. Defaults to ``True``.
    cmap : str | None
        The matplotlib colormap to use. Defaults to None, which means the
        colormap will default to matplotlib's default.
    n_cols : int | None
        CSD matrices are plotted in a grid. This parameter controls how
        many matrix to plot side by side before starting a new row. By
        default, a number will be chosen to make the grid as square as
        possible.
    show : bool
        Whether to show the figure. Defaults to ``True``.

    Returns
    -------
    fig : list of Figure
        The figures created by this function.
    r   N)rˆ  Úcohz'"mode" should be either "csd" or "coh".r*   FT)ZmegÚeegr-   r.   r�  Úgradc                    s*   g | ]"}ˆ| ˆ j krˆ j  ˆ| ¡‘qS r,   r7   r;   ©rˆ  r=   r,   r5   r6      s    ÿzplot_csd.<locals>.<listcomp>c                    s*   g | ]"}ˆ| ˆ j krˆ j  ˆ| ¡‘qS r,   r7   r;   rŒ  r,   r5   r6     s    ÿc                    s*   g | ]"}ˆ| ˆ j krˆ j  ˆ| ¡‘qS r,   r7   r;   rŒ  r,   r5   r6     s    ÿZEEGZMagnetometersZGradiometersrˆ  u   ÂµVÂ²u	   fTÂ²/cmÂ²u   fTÂ²)rŠ  r‹  r�  g   ¢”mBg52·ô­TEgêŒ 9Y>)FzCross-spectral densityr‰  Z	CoherencerŠ  r   r#   gš™™™™™@rQ   r:   rS   )rV   rW   rT   rU   z%.1f-%.1f Hz.z%.1f Hz.r-  )rp   c                 S   s   g | ]}|D ]}|‘qqS r,   r,   )r1   Zax_rh  r,   r,   r5   r6   B  s       )r¾   ZCSDz (%s))%rx   ry   r«   r   rD   r|   r­   rA   r*   Zfrequenciesr÷   Úceilr   rp  rþ   r‚   r³   Úget_datar…   ÚgetZdiagr�   Znewaxisr°   r„   rƒ   r†   r·   r¸   Z_is_sumÚ	set_titler‹   ZsuptitlerŠ   r‰   Ú	set_labelr'   )%rˆ  r4   Úmoder‰   rW   Zn_colsrŽ   r�   Zsel_eegZsel_magZsel_gradZidx_eegZidx_magZidx_gradÚindicesr>   r?   r@   Zn_freqsZn_rowsr  ÚindrY   rH   rc   r“   Zcsd_matsr»   r   ZpsdrU   r¨   Zmatr¾   r–   ÚcbÚlabelr,   rŒ  r5   Úplot_csdÏ  s¤    $
ÿ
ÿ
ÿÿÿÿ






ÿ


2
ÿ

ÿ





r—  c                 C   s
  ddl m} t| ƒdd… }tdddd�}tdd	d
�}|dk}|r\|jt|ƒddd�\}}n|d  ¡ }t|ƒt|ƒkrœtdt|ƒ› dt|ƒ› d|› d�ƒ‚| dd¡ d}t	||ƒD �]\}	}
|	 
d¡\}}|dkrÚdn
td | }|dkrøtdd�ntƒ }|
j| d | |	 |d  f|Ž}|�sRt	|| d ƒD ]\}}| |› d�¡ �q2d}td | }d|k�rtd|› d �n|}t|| › d!|| › �|dk�rœd"n|› d#�d$�}|�s¼|jd%d&� |
jf |Ž q¶|�r|
jd%d&� | ¡  |jd'd(d)d*d+d,� |jd-d.d/� |S )0u9  Plot time-varying SNR estimates of the HPI coils.

    Parameters
    ----------
    snr_dict : dict
        The dictionary returned by `~mne.chpi.compute_chpi_snr`. Must have keys
        ``times``, ``freqs``, ``TYPE_snr``, ``TYPE_power``, and ``TYPE_resid``
        (where ``TYPE`` can be ``mag`` or ``grad`` or both).
    axes : None | list of matplotlib.axes.Axes
        Figure axes in which to draw the SNR, power, and residual plots. The
        number of axes should be 3Ã— the number of MEG sensor types present in
        ``snr_dict``. If ``None`` (the default), a new
        `~matplotlib.figure.Figure` is created with the required number of
        axes.

    Returns
    -------
    fig : instance of matplotlib.figure.Figure
        A figure with subplots for SNR, power, and residual variance,
        separately for magnetometers and/or gradiometers (depending on what is
        present in ``snr_dict``).

    Notes
    -----
    If you supply a list of existing `~matplotlib.axes.Axes`, then the figure
    legend will not be drawn automatically. If you still want it, running
    ``fig.legend(loc='right', title='cHPI frequencies')`` will recreate it,
    though you may also need to manually adjust the margin to make room for it
    (e.g., using ``fig.subplots_adjust(right=0.8)``).

    .. versionadded:: 0.24
    r   Nr   ZSNRz
cHPI powerzResidual variance)ÚsnrÚpowerÚresidZmagnetometersZgradiometers)r�  r‹  r#   T)Zsharexzaxes must be a list of z axes, got length z (z).r¦   Fr’   r˜  r@   rš  re   rª   r¬   Zfreqsz Hzr?   ú/ú(ú)r„  ZdBõ   Â²)rY   rt   rŸ   )rv   rX  gffffffê?g333333³?gffffffî?gffffffæ?)rè   r[   rç   rp   rò   r[   zcHPI frequencies)r.  rY   )rx   ry   rE   rD   r‚   rA   rr  r«   Zset_size_inchesrþ   Úsplitr   rŒ   r‘  r‡  r‡   Zalign_ylabelsrŠ   r6  )Zsnr_dictr“   r�   Z
valid_keysr>   Z
full_namesZaxes_was_nonerc   Zlegend_labels_existrB   r¾   rH   rú   r™   Zplot_kwargsÚlinesÚliner¨   r˜   Z
set_kwargsr,   r,   r5   Úplot_chpi_snrQ  sN    !$ÿÿÿr¢  )r,   TFTTN)NNNFT)	NrÀ   NNNTTr  T)	Nr   NNNTTr(  N)NT)rK  T)N)Nrˆ  TNNT)N)OÚ__doc__rz   r  r   Ú	itertoolsr   Úos.pathÚpathr  r  Úcollectionsr   Únumpyr|   Údefaultsr   Z_freesurferr   r   r	   r
   Zrankr   Zsurfacer   Zio.constantsr   Zio.projr   Zio.pickr   r   r   r   Zsource_spacer   r   r   Z
transformsr   r   Úutilsr   r   r   r   r   r   r   r   r    r!   Úfilterr"   r$   r%   r&   r'   r(   r)   rL   r›   r¿   r  r'  r  rA  rI  rJ  rM  rW  rZ  r[  Z_DEFAULT_ALIMr‚  ru  r2  r—  r¢  r,   r,   r,   r5   Ú<module>   s¾   ,     ÿz      ÿ
q   ý 9             þw         þ 
$

    ýý `   þ
b    ÿ 