I do RMSF analysis and as a results I have list of floats (0.1, 0.3, etc.) and I would like to do a histogram where are bins of defined ranges of the floats. Then I want to have each range of float with corresponding color. I tried to do it with analogies of this script:
JavaScript
x
20
20
1
from MDAnalysis.analysis.rms import RMSF
2
import matplotlib.pyplot as plt
3
import numpy as np
4
5
fig, ax = plt.subplots()
6
data = rmsfer.rmsf
7
8
N, bins, patches = ax.hist(data, edgecolor='white', linewidth=1)
9
10
for i in np.arange(0.3,0.8):
11
patches[i].set_facecolor('navy')
12
for i in np.arange(0.8,1.3):
13
patches[i].set_facecolor('cyan')
14
for i in np.arange(1.3,1.8):
15
patches[i].set_facecolor('yellow')
16
for i in np.arange(1.8,2.3):
17
patches[i].set_facecolor('orange')
18
for i in np.arange(2.3,3.5):
19
patches[i].set_facecolor('red')
20
I know that there is problem with the float and tried to fix it with numpy and np.arange, but of course it is not so easy for me as I am new to python. Any suggestion, please?
Advertisement
Answer
You would want to pass bins
into ax.hist
:
JavaScript
1
5
1
fig,ax = plt.subplots()
2
N, bins, patches = ax.hist(data,bins=[0.3, 0.8,1.3,1.8,2.3,3.5],edgecolor='white')
3
for (p,c) in zip(patches, ['navy','cyan','yellow','orange','red']):
4
p.set_facecolor(c)
5
Output: