3 Pa@spdZddljZddlmZddlZddlZ dddZ d d Z dd dZ dddZ dddZddZd ddZdS)!z Plotting utilities N)GridSpeccCsrddg|d}tjd|tjd|dtjd|dtjd|dtjd |dtjd |d tjd |dd S)zV Sets font size for matplotlib From: https://stackoverflow.com/a/39566040 z sans-serifArial)familyz sans-serifsizefontaxes)Z titlesize) labelsizextickyticklegend)fontsizefigureN)r )pltrc)Z SMALL_SIZEZ MEDIUM_SIZEZ LARGE_SIZEr r..\utils\plot_utils.pyset_font_sizes s rc CsJxD|D]<}|j}tjdj||j|jd|fd ddddqWd S) z Attach a text label above each bar in *rects*, displaying its height. From: https://matplotlib.org/3.1.1/gallery/lines_bars_and_markers/barchart.html z{}rz offset pointscenterbottom)xyxytext textcoordshavaN)rr) get_heightrannotateformatget_x get_width)rectsrectheightrrr autolabels  r'Ftab:bluecCs:|j}|r|t|}tj|j||d}|r6t|dS)z Given a pandas series of cateogorical values, makes a bar plot of the frequency of each value, with optional count label )colorN) value_countslenrbarindexr')serZ num_labelr)fractionZval_ctsr$rrrplot_value_counts_of_series(s  r0magmac Cs&tjtj|||ddddi|ddS)zW Helper for plot_scaled_hmap, plotting a single connectivity matrix (mat) rrlabelz$\log_{10}$ # synapses)axcmapvminvmaxcbar_kwscbar_axN)snsheatmapnplog10)matr3r8r4rrrplot_mat9s r>jetcst}fddt|D}tj|f}d|d<t||||ddd}|jddd d g} d } g} xt|D]} g} xt|D]}|j|| |f}|j| |f}t||| |d |j g|j g|j d |j g|j g|jd |jdd| d|j|jdd| d|jdd| d|j|jdd| d| j|q~W| j| qlWxBt|D]6} | | dj || | |d| j|| qhWdS)zs Intended use is to plot connectivity matrix for ORNs, LNs, u/mPNs, adding higher visual weight to LNs cs&g|]}|djt|qS)zs ({}))r!r+).0i)neur_set_names neur_setsrr Lsz$plot_scaled_hmap..rg?) width_ratios height_ratioswspacehspacegq= ףp?g333333?gQ?g?r)r4rk)yr) linewidth)xr)rMN)r+ranger;onesradd_axes add_subplotlocr>set_yticklabels set_yticks set_ylabelset_xticklabels set_xticks set_xlabelaxhlineshapeaxvlineappend)figZconmatrCrBr4Zn_typesZneur_full_namesZp_ratiosgsr8lwaxsrAZax_rowsjr3r=r)rBrCrplot_scaled_hmapEs>    rccsg}g}|j}x|D]}|j}|r|ddkrTtj|ddtd}|j|q|ddkrgx.z///rcs>g|]6}ddd|dd|dddgqS)rrEr)r@rK)facerrrDscsg|]}|ddqS)rrEr)r@rb)rjrrrDs) splitlinessplitr;arrayfloatr]rOr+replaceextend)odataverticesfaceslineslineslistvertexrKr)rjrobj_data_to_mesh3dus$    * ("rx皙?rJc Cstt||}|tjjt||dd}t|dkrr|j|dddf|dddf|dddfdd||dn>|j|dddf|dddf|dddfdd|||d dS) z Given vertices of a mesh (computed from obj_data_to_mesh3d), and a number of vertices (n_subsample), plots in 3d the points of the mesh F)rorNrEro)r`alphar2)r`r|r2r))minr+r;randomchoiceplot)r3rrZ n_subsampler|r2r)vertsrrrplot_mesh_verticess ..r)rrr)Fr(F)r1)r?)ryrzrJrJ)__doc__matplotlib.pyplotpyplotrmatplotlib.gridspecrnumpyr;seabornr9rr'r0r>rcrxrrrrrs     0