Member-only story

Simulate the spread of a virus using matplotlib and Replit

Crystal X
2 min readMar 23, 2022

--

In my last post I carried out a code review of John Conway’s Game of Life, which is a zero person animated game. The link to that post can be found here:- https://tracyrenee61.medium.com/playing-conways-game-of-life-on-replit-4591ab603149

I have been so impressed with the animations that matplotlib can carry out that I searched for another type of animation, which is a simulation. In this post I intend to carry out a code review of a virus spreader, which also uses matplotlib to animate the spread of a hypothetical virus. I found the code for the virus spreader in a YouTube video entitled, “Simulating COV19 Using Python, Numpy and Matplotlib”. I was unable to get the program to run on Google Colab, being the interpreter that I normally use, but I was able to run it satisfactorily on Replit.

I am totally new to making simulations, so I can only carry out a code review at this point in my programming education. The code review is as follows:-

  1. Import libraries, being numpy and matplotlib.
  2. Assign values for colours, being grey, red, green and black.
  3. Set up the parameters for COV19.
  4. Define class Virus.
  5. Define __init__ function.
  6. Define initial population of 4,500.

--

--

Crystal X
Crystal X

Written by Crystal X

I have over five decades experience in the world of work, being in fast food, the military, business, non-profits, and the healthcare sector.

No responses yet