user3598726 - 8 months ago 36

Python Question

I'm building a little simulation based on this experiment:

https://www.youtube.com/watch?v=plVk4NVIUh8 , which shows the evolution of a bacteria over time.

I have initialized some bacteria with random resistance at the edge of a petri dish:

As the bacteria spreads, the contrast from the non occupied space is less and less, after a 100 generation it becomes like this:

I use plt.matshow(Map) to make the pictures, where Map is a 2D numpy array, with bacteria resistance values (always bigger than 0), the non occupied space is represented as 0. I tried different colormaps, but it did not help. My aim is to make the non occupied space some constant dark color,

the infected space some light color, with conrtast to notice the different resistance values.

Can you help me with that?

Answer

I was able to make the visulaization better, using logaritmic normalization: Let's say my bacteriaMap has really different resistancevalues:

```
import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
size=10
a = rand(size, size) * 0.2
b = rand(size, size) * 2
c = rand(size, size) * 20
sumMap = np.concatenate((a,b,c), axis=1)
```

sumMap is the numpy array to plot, with small, medium and big numbers. Building up colormap and normalizer:

```
maxval=np.max(sumh)
minval=np.min(sumh)
colormap = plt.get_cmap('magma')
norm = mpl.colors.LogNorm(vmax=maxval, vmin=minval)
```

If I use the normalization the map loks like this:

```
img = plt.pcolormesh(sumh, cmap=colormap, norm=norm)
img.figure.show()
```

If I don't:

```
img = plt.pcolormesh(sumh, cmap=cmap, )
img.figure.show()
```