对于不同分子的不同方法,我有几个RMSD值(测量两种分子结构的差异)。我想在极坐标图中绘制它们,因此每个径向线代表一个分子,其中绘制了所有不同的RMSD值。 问题是我希望每种方法都能为不同的分子显示相同的颜色。到目前为止我得到了这个
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.pyplot import cm
pi = np.pi
N=11
list = np.zeros(N)
list += pi
color=iter(cm.rainbow(np.linspace(0,1,N)))
functionals = ['PBE', 'PBE-D3', 'PBE0', 'PBE0-D3', 'TPSS', 'TPSS-D3', 'TPSSh', 'B3LYP', 'B3LYP-D3', 'LCwPBE', 'LCwPBE-D3']
comp1 = list
comp2 = list/2
RMSD_comp1 = np.random.rand(N)
RMSD_comp2 = np.random.rand(N)
ax = plt.subplot(111, projection='polar')
for i in range(len(functionals)):
c=next(color)
for func in range(len(functionals)):
ax.scatter(comp1, RMSD_comp1, c=c)
ax.scatter(comp2, RMSD_comp2, c=c)
ax.set_alpha(0.75)
plt.show()
但是我得到了这个: 理想的是,当引用相同的方法时,不同的径向线中的每个RMSD值显示相同的颜色。
答案 0 :(得分:1)
我设法解决了这个问题。我会留下答案,以防万一其他人发现它有用。
import numpy as np
import matplotlib.pyplot as plt
from pylab import *
colors = [ 'r', 'r', 'g', 'g', 'b','b', 'orange', 'y', 'y', 'm', 'm']
m = ['o', 'v', '<', '>', 's', '*', '^', 'x', 'p', 'h', '8']
functionals = ['PBE', 'PBE-D3', 'PBE0', 'PBE0-D3', 'TPSS', 'TPSS-D3',
'TPSSh', 'B3LYP', 'B3LYP-D3', 'LCwPBE', 'LCwPBE-D3']
list_compounds = ['1', '2', '3',
'4', '8', '9', '10', '12', '13',
'6',
'5', '7', '11', '14', '16a', '16b',
'17', '18' ] # U(III), U(IV), U(V), U(VI) and dimers
''' This section divides the chart in equidistant parts and defines the RMSD values calculated for each compound with the != functionals '''
N= 5 #number of compounds
mult = 360./N
angles = np.arange(N)*mult
''' The three lists correspond to the results coming from Gaussian09_d, NWChem16 and ADF_2016 respectively '''
# *** U(III) ***
RMSD_comp1 = [ [ 0.2116, 0.2914, 10, 10, 0.1959, 0.3102, 0.2301, 0.1691, 0.3176, 10, 10 ], [ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 ],
[ 0.2217, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 ] ] #Gaussian / NW / ADF
RMSD_comp2 = [ [ 0.4400, 10, 0.3817, 10, 1.334, 10, 0.8540, 10, 10, 0.5016, 10 ], [ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 ], [ 0.3907, 0.3503, 10, 10, 10, 10, 10, 10, 10, 10, 10 ] ]
RMSD_comp3 = [ [ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 ],
[ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 ],
[ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 ] ]
# *** U(IV) ***
RMSD_comp4 = [ [ 0.3072, 0.1692, 0.3212, 0.1748, 0.3985, 0.1584, 0.2595, 0.3111, 0.1382, 0.1956, 0.1378 ],
[ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 ],
[ 0.2000, 0.1443, 10, 10, 10, 10, 10, 10, 10, 10, 10 ] ]
RMSD_comp8 = [ [ 0.7000, 0.6039, 0.5817, 0.5000, 0.7124, 0.5223, 1.2091, 0.6423, 0.4859, 1.0559, 0.7471 ],
[ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 ],
[ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 ] ]
RMSD_comp9 = [ [ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 ],
[ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 ],
[ 10, 10, 10, 10, 10, 10, 10, 10, 10, 10, 10 ] ]
compounds = np.vstack( ( RMSD_comp1, RMSD_comp2, RMSD_comp3, RMSD_comp4, RMSD_comp8, RMSD_comp9 ) )
# *** Plot of GAUSSIAN_09-d results ***
fig = plt.figure(figsize=(10,12))
ax = plt.subplot(111, projection='polar')
plt.title('RMDS Gaussian', fontsize=18, x=0.51, y=1.07)
angle=0
for comp in range(0, 3*N, 3):
for func in range(len(functionals)):
ax.scatter([np.radians(angles[angle])], compounds[comp][func], c=colors[func], s=75, marker=m[func], label=functionals[func] if comp == 0 else "")
angle+=1
ax.set_alpha(0.75)
legend = ax.legend( bbox_to_anchor=(0.10, -0.32, 0.85, 0.25), borderaxespad=0, mode="expand", fontsize='small', scatterpoints=1, ncol=6, frameon=False)
ax.set_thetagrids(angles, labels=list_compounds, fontsize=12, rotation=0, weight='bold', color="black")
ax.set_rgrids([0.2, 0.4, 0.6, 0.8, 1.0, 1.2], angle=15.)
ax.set_rmax(1.4)
fig.tight_layout()
plt.close('all')
获得