gpt4 book ai didi

Python极坐标图;给定数据集的每个点使用不同的颜色

转载 作者:太空宇宙 更新时间:2023-11-03 16:36:31 25 4
gpt4 key购买 nike

我有几个针对不同分子的不同方法的 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()

但是我得到了这个: Chart plot理想的情况是,当引用相同的方法时,不同径向线中的每个 RMSD 值显示相同的颜色。

最佳答案

我设法解决了。我会留下答案,以防其他人发现它有用。

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')

获取

enter image description here

关于Python极坐标图;给定数据集的每个点使用不同的颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37168789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com