Popular recipes tagged "meta:requires=matplotlib.pyplot"http://code.activestate.com/recipes/tags/meta:requires=matplotlib.pyplot/2015-04-29T07:09:33-07:00ActiveState Code RecipesLecture 1: Applications of Python in Bioinformatics: Visualizing Protein (Python) 2015-04-29T07:09:33-07:00Devashish Dashttp://code.activestate.com/recipes/users/4192116/http://code.activestate.com/recipes/579050-lecture-1-applications-of-python-in-bioinformatics/ <p style="color: grey"> Python recipe 579050 by <a href="/recipes/users/4192116/">Devashish Das</a> (<a href="/recipes/tags/3d/">3d</a>, <a href="/recipes/tags/bioinformatics/">bioinformatics</a>, <a href="/recipes/tags/plots/">plots</a>, <a href="/recipes/tags/protein/">protein</a>, <a href="/recipes/tags/python/">python</a>). </p> <p>This code reads 1qlz.pdb protein file can be downloaded from <a href="http://www.rcsb.org/pdb/files/1QLZ.pdb" rel="nofollow">http://www.rcsb.org/pdb/files/1QLZ.pdb</a> and plots a 3D graph using maplotlib library. For mystery write to me: <a href="mailto:devashish.das@educept.com">devashish.das@educept.com</a></p> <pre class="prettyprint"><code>__author__ = Devashish Das __contact__ = +91-9964218681 __email__ = <a href="mailto:deavshish.das@educept.com">deavshish.das@educept.com</a> __website__ = <a href="http://www.educept.com">http://www.educept.com</a> </code></pre> Monte Carlo Engine : Simple Head Tail Model (Python) 2014-04-27T17:25:25-07:00alexander bakerhttp://code.activestate.com/recipes/users/4166679/http://code.activestate.com/recipes/578868-monte-carlo-engine-simple-head-tail-model/ <p style="color: grey"> Python recipe 578868 by <a href="/recipes/users/4166679/">alexander baker</a> (<a href="/recipes/tags/carlo/">carlo</a>, <a href="/recipes/tags/monte/">monte</a>, <a href="/recipes/tags/python/">python</a>, <a href="/recipes/tags/strategy/">strategy</a>). Revision 2. </p> <p>Wanted to implement something that shows how the simple framework can be used to investigate a basic heads and tail game. The betting strategy can be varied simply by changing the logic in the ontrail() method. This currently tests the double or quits strategy. Run it to see how many </p> Genetic Algorithm Neural Network in Python Source Code (Python) 2012-08-16T16:31:12-07:00David Adlerhttp://code.activestate.com/recipes/users/4182015/http://code.activestate.com/recipes/578241-genetic-algorithm-neural-network-in-python-source-/ <p style="color: grey"> Python recipe 578241 by <a href="/recipes/users/4182015/">David Adler</a> (<a href="/recipes/tags/artificial_intelligence/">artificial_intelligence</a>, <a href="/recipes/tags/neural/">neural</a>, <a href="/recipes/tags/neural_network/">neural_network</a>). </p> <p>A simple genetic algorithm neural network. </p> Artificial Neuroglial Network (ANGN) (Python) 2012-10-02T16:18:36-07:00David Adlerhttp://code.activestate.com/recipes/users/4182015/http://code.activestate.com/recipes/578242-artificial-neuroglial-network-angn/ <p style="color: grey"> Python recipe 578242 by <a href="/recipes/users/4182015/">David Adler</a> (<a href="/recipes/tags/artificial_intelligence/">artificial_intelligence</a>, <a href="/recipes/tags/genetic_algorithm/">genetic_algorithm</a>, <a href="/recipes/tags/genetic_algorithms/">genetic_algorithms</a>, <a href="/recipes/tags/neural/">neural</a>, <a href="/recipes/tags/neural_networks/">neural_networks</a>). Revision 5. </p> <p>This is an attempt at emulating the algorithm from these scientific articles:</p> <ol> <li><a href="http://www.hindawi.com/journals/cmmm/2012/476324/">2011 - Artificial Astrocytes Improve Neural Network Performance</a></li> <li><a href="http://www.plosone.org/article/info%3Adoi%2F10.1371%2Fjournal.pone.0019109">2012 - Computational Models of Neuron-Astrocyte Interactions Lead to Improved Efficacy in the Performance of Neural Networks</a></li> </ol> <p>The objective of the program is to train a neural network to classify the four inputs (the dimensions of a flower) into one of three categories (three species of flower), (taken from the <a href="http://archive.ics.uci.edu/ml/datasets/Iris">Iris Data Set</a> from the UCI Machine Learning Repository). This program has two learning phases: the first is a genetic algorithm (supervised), the second is a neuroglial algorithm (unsupervised). This ANGN is a development of a previous program only consisting of a genetic algorithm which can be found <a href="http://code.activestate.com/recipes/578241-genetic-algorithm-neural-network-in-python-source-/">here</a>.</p> <p>The second phase aims to emulate astrocytic interaction with neurons in the brain. The algorithm is based on two axioms: a) astrocytes are activated by persistent neuronal activity b) astrocytic effects occur over a longer time-scale than neurons. Each neuron has an associated astrocyte which counts the number of times its associated neuron fires (+1 for active -1 for inactive). If the counter reaches its threshold (defined as <code>Athresh</code>) the astrocyte is activated and for the next x iterations (defined as <code>Adur</code>) the astrocyte modifies the incoming weights to that particular neuron. If the counter reached a maximum due to persistent firing the incoming weights are increase by 25% for the proceeding <code>Adur</code> iterations; conversely if the counter reached a minimum due to persistent lack of firing the weights are decreased by 50% for the following <code>Adur</code> iterations). For a detailed description of the algorithm see the linked articles. For a general understanding of how this program was coded look at the pseudo-code/schematic <a href="http://commons.wikimedia.org/wiki/File:ANGN_schematic.png">here</a>.</p> <p>Any comments for improvements are welcome. There are several issues in this program which require addressing, please scroll down below code to read about these issues.</p> Test various OpenCV feature detectors in Python (Python) 2012-09-13T16:07:21-07:00J W Jhttp://code.activestate.com/recipes/users/4181154/http://code.activestate.com/recipes/578261-test-various-opencv-feature-detectors-in-python/ <p style="color: grey"> Python recipe 578261 by <a href="/recipes/users/4181154/">J W J</a> (<a href="/recipes/tags/feature_detection/">feature_detection</a>, <a href="/recipes/tags/opencv/">opencv</a>). </p> <p>Iterates through all feature detectors (that didn't crash my computer) and plots the point results.</p> An extensible Conway's Game of Life (Python) 2011-12-05T11:45:45-08:00Filippo Squillacehttp://code.activestate.com/recipes/users/4174931/http://code.activestate.com/recipes/577976-an-extensible-conways-game-of-life/ <p style="color: grey"> Python recipe 577976 by <a href="/recipes/users/4174931/">Filippo Squillace</a> (<a href="/recipes/tags/animation/">animation</a>, <a href="/recipes/tags/game/">game</a>, <a href="/recipes/tags/life/">life</a>). </p> <p>This program is an extensible Conway's game of life. It allows to define different type of grid (for example 2D or 3D) and more complex rules. Each grid inherits an Abstract grid that implement the method (next()) to pass for the next configuration. Furthermore, each element can be whatever type. In this example I designed Grid2DBool that represent the simple Conway's game of life, but could be possible to develop and easily implement more complex grids and rules.</p> <p>Note: The demo save also the animation in a file .mp4 and plot it through pyplot. The demo could take long time because of storing all the configurations before showing the animation. Therefore, the visualization can be improved using other libraries (as wxpython) that paint the configuration of the grid once it's created. With a more complex view it's convenient to apply MVC pattern declaring the model AbstractGrid as the Observable class.</p> Benford's Law demo (Python) 2010-10-19T10:56:51-07:00Glenn Hutchingshttp://code.activestate.com/recipes/users/4175415/http://code.activestate.com/recipes/577431-benfords-law-demo/ <p style="color: grey"> Python recipe 577431 by <a href="/recipes/users/4175415/">Glenn Hutchings</a> (<a href="/recipes/tags/benford/">benford</a>, <a href="/recipes/tags/matplotlib/">matplotlib</a>, <a href="/recipes/tags/plotting/">plotting</a>). </p> <p>Here's a simple program to demonstrate <a href="http://en.wikipedia.org/wiki/Benford%27s_law">Benford's Law</a>, which also shows the simple power of <a href="http://matplotlib.sourceforge.net">matplotlib</a>. It reads from a bunch of files (or stdin, if none specified), extracts the leading digits of all number-like strings found, and plots the distribution in a window together with the expected result if Benford's law applies.</p> Stacked graphs using matplotlib (Python) 2009-01-26T08:11:59-08:00Anand Patilhttp://code.activestate.com/recipes/users/4168675/http://code.activestate.com/recipes/576633-stacked-graphs-using-matplotlib/ <p style="color: grey"> Python recipe 576633 by <a href="/recipes/users/4168675/">Anand Patil</a> (<a href="/recipes/tags/broadband/">broadband</a>, <a href="/recipes/tags/matplotlib/">matplotlib</a>, <a href="/recipes/tags/mobile/">mobile</a>, <a href="/recipes/tags/stacked_graph/">stacked_graph</a>, <a href="/recipes/tags/stream_graph/">stream_graph</a>). </p> <p>Creates stacked graphs (sometimes known as stream graphs, apparently) as recommended by Byron and Wattenberg, <a href="http://www.leebyron.com/else/streamgraph/download.php?file=stackedgraphs_byron_wattenberg.pdf" rel="nofollow">http://www.leebyron.com/else/streamgraph/download.php?file=stackedgraphs_byron_wattenberg.pdf</a></p>