Home > Blockchain >  Matplotlib overlay bimodal histograms
Matplotlib overlay bimodal histograms

Time:11-08

I am trying to put three "bimodal/binary histograms" on the same plot, labeled, and with the actual values instead of bins. Not sure if it makes sense... However, I would like to show the only 2 values that are present in each vector x1, x2 and x3.

Here is the code:

import matplotlib.pyplot as plt

x1 = [0.003996747444034554, 0.003996747444034554, 0.003996747458586469, 0.003996747444034554, 0.003996747444034554, 0.003996747444034554, 0.003996747458586469, 0.003996747444034554, 0.003996747444034554, 0.003996747444034554]
x2 = [0.003996536252088845, 0.003996536252088845, 0.003996536252088845, 0.003996536310296506, 0.003996536252088845, 0.003996536252088845, 0.003996536252088845, 0.003996536252088845, 0.003996536252088845, 0.003996536252088845]
x3 = [0.003996643703430891, 0.003996643703430891, 0.003996643703430891, 0.003996643703430891, 0.003996643703430891, 0.003996643761638552, 0.003996643703430891, 0.003996643703430891, 0.003996643703430891, 0.003996643703430891]

fig, axs = plt.subplots(1,3, figsize=([7,4]), sharey = True)
axs[0].hist(x1)
axs[1].hist(x2)
axs[2].hist(x3)
plt.tight_layout()

plt.figure(figsize=([7,4]))
plt.hist([x1,x2,x3])

Figure 1 is the plot of each histogram (x1, x2 and x3): enter image description here

Figure 2 is the result of plotting all at once: enter image description here

CodePudding user response:

The difference within each vector are much smaller than the differences between the vectors' means, therefore both histogram bars for each vector coincide.
For this particular case you could use a enter image description here

(you'll need to zoom in to see the difference between the two x-positions of each vector)

  • Related