Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
96135 views
�
�j�UV�
@s-dZddljZddlZdd�Zdd�Zd(ddd	�Zdddd
d�Z	dd
�Z
dddddd�Zddd�Zdddddd�Z
dddddd�Zdd�Zdd d!�Zed"kr)d#d$d%d&d'd#d$d%d&d'g
dZee�ee�ndS))z6
Created on Fri May  2 12:21:40 2014

@author: rlabbe
�NcCs�d}x[|D]S}tj|dg|gd|dgddd|dd	dd
d�|d7}q
Wtjdd�tj|d|d�t�tj�jjjg�tj	�dS)
Ng�?r�xerr��fmt�o�label��capthick�capsize�
g�������?)
�plt�errorbar�ylim�xlim�show_legend�gca�axes�yaxis�	set_ticks�show)�bars�xlims�i�bar�r�./code/book_plots.py�plot_errorbars
s
CrcCstjdddd�dS)N�loczcenter left�bbox_to_anchorr��?)rr)r�legendrrrrrsrrcCs�tj�tj�}tjt|��}|j||dd�|rWtj|�ntj|d|�|dk	r�tj	|�ndS)N�colorz#30a2dag�������?)
r�clar�np�arange�lenrr
�xticks�title)�posr
r&�ax�xrrr�bar_plots
r*cCsX|dk	rtj|�n|dk	r8tj|�n|dk	rTtj|�ndS)zL helps make code in book shorter. Optional set title, xlabel and ylabel
    N)r�xlabel�ylabelr&)r&r)�yrrr�
set_labels*sr.cCs*tj�j|�tj�j|�dS)z\ helper function to make code in book shorter. Set the limits for the x
    and y axis.
    N)rr�set_xlim�set_ylim)r)r-rrr�
set_limits5sr1�rrZMeasurementscKsvtjdd�|dk	rJtj||d|d|ddd||�n(tj|d|d|ddd||�dS)	zW Helper function to give a consistant way to display
    measurements in the book.
    �tightTNr �lw�lsz--r)r�	autoscale�plot)�xs�ysr r4r�kwargsrrr�plot_measurements>s.r;g�?cCs�tj|�|}tj|dddddd�tj|dddddd�tjtt|��||ddd	d
�dS)z� plots standand deviation given in Ps as a yellow shaded region. One std
    by default, use stds for a different choice (e.g. stds=3 for 3 standard
    deviations.
    r �kr5�:r4r�	facecolorz#ffff00�alphag333333�?N)r"�sqrtrr7�fill_between�ranger$)ZPsZstds�stdrrr�plot_residual_limitsVs
 rDZTrackr<cKsf|dk	r:tj||d|d|ddd||�n(tj|d|d|ddd||�dS)Nr r4r5r=r)rr7)r8r9r�cr4r:rrr�
plot_trackds.rFz#013afe�Filterc		Ks�|dkr'|}tt|��}ntj||d|d||�|dkrVdStj|�}tj|�}||}||}tj|||dddddd�tj|||dddddd�tj|||dd	d
d�dS)Nr r�	linestyler=r<r4rr>�yellowr?g�������?)rBr$rr7r"�asarrayr@rA)	r8r9rEr�varsr:rCZstd_topZstd_btmrrr�plot_filterks

&&rLcCs�tj|�d}tj||||||||g�}tj||||||||g�}tj|||d|�dS)z\
    Draws a square-shaped blob with the given area (< 1) at
    the given coordinates.
    r�	edgecolorN)r"r@�arrayr�fill)r)r-�areaZcolour�hsZxcornersZycornersrrr�_blob�s++rRc
	Cs�d}tj�rtj�ntj�|j\}}|s|dtjtjtjtj	|���tjd��}ntj
tjd||dg�tjdd||g�d�tjd�tjd�x�t
|�D]�}x�t
|�D]�}|d}|d}|||f}	|	dkrXt|d||dtd|	|�d	�q�|	dkr�t|d||dtd|	|�d
�q�q�Wq�W|r�tj�ndS)z�
    Draws a Hinton diagram for visualizing a weight matrix.
    Temporarily disables matplotlib interactive mode if it is on,
    otherwise this takes forever.
    Frr�gray�off�equalrg�?�white�blackN)r�
isinteractive�ioff�clf�shaper"�ceil�log�max�absrOrN�axisrBrR�min�ion)
�WZ	maxweightZreenable�height�widthr)r-�_x�_y�wrrr�hinton�s:

>






ri�__main__g�>�$E��?g�L����?g���\G�?g�,�Wc��?g1�I�+�?)rr)�__doc__�matplotlib.pyplot�pyplotr�numpyr"rrr*r.r1r;rDrFrLrRri�__name__�prrrr�<module>s$	
(