How to create subtitles of images made using the hist () function in matplotlib / pyplot / numpy?

I would like to create four subtitles of images made using the hist () function using matplotlib, pyplot and / or numpy. (I'm not quite sure what the differences are between these things. Usually I just import everything I need based on an example.)

In my case, I have a list consisting of four lists that describe the number of virus particles at the end of some simulation involving a population of viruses. Each of these four lists contains 30 (integer) numbers. Most of the numbers are from 0 to 10, or from 450 to 600 (which means that in the first case the virus population (almost) died out or that in the latter case the virus population survived and adapted to certain changing conditions).

In each of the subheadings created by the hist () function, I would like to show how often the virus population (almost) dies, adapts, or is somewhere in between. Therefore, I would like to create four snapshot histograms of the subtitle, which are combined into one big picture. The x-axis shows the population at the end of the simulation, and the y-axis shows the frequency of the virus population having this number of viral particles.

In addition, I would like to provide each subheading with a heading and designate the x and y axes.

I've tried this many times already by looking at the documentation for the hist () function and the subplot options in pyplot, but I could not figure out how to combine these parameters. Could you give me a small example of this? Then I can probably extrapolate how to set up an example for my situation.

+4
1

, matplotlib.
add_subplot subplots.

, ,

import matplotlib.pyplot as plt
import numpy as np

data=np.random.random((4,10))
xaxes = ['x1','x2','x3','x4']
yaxes = ['y1','y2','y3','y4']
titles = ['t1','t2','t3','t4'] 

f,a = plt.subplots(2,2)
a = a.ravel()
for idx,ax in enumerate(a):
    ax.hist(data[idx])
    ax.set_title(titles[idx])
    ax.set_xlabel(xaxes[idx])
    ax.set_ylabel(yaxes[idx])
plt.tight_layout()

, , , enter image description here

+12

All Articles