import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
file1=pd.read_csv('/Users/guimei-liu/Desktop/oc2_filter2.csv')
file2=file1.dropna(subset=['bp_rp'])
prob=np.array(file2['probs_final'])
ind=(prob>=0.)
file=file2[ind]
plx1=file['parallax']
plx_err1=file['parallax_error']
probs=np.array(file['probs_final'])
g=np.array(file['phot_g_mean_mag'])
bp_rp=np.array(file['bp_rp'])
fig,ax = plt.subplots()
plt.axis([min(bp_rp),max(bp_rp),min(g),max(g)+1])
ax.invert_yaxis()
plt.xlabel('$G_{BP}-G_{RP}$')
plt.ylabel('$G$')
#重点在与此处需要x,y,z捆绑到一起,c表示一个长度与x,y相同的浮点数数组,系统会自动使用此数组给每个点上色,cmap选颜色
sc=plt.scatter(bp_rp,g,probs,c=probs,cmap='Reds')
#shrink(0-1)设置colorbar的长度,aspect设置colorbar的长宽比例,ticks
cbar=plt.colorbar(sc,label='probility',shrink=0.75,aspect=12,ticks=np.arrange(0,1,0.2))
#把colorbar当作类似subplot的对象,可以用subplot特有的函数进行调整label
sc.ax.set_ylabel('probability')
plt.show()
colorbar相当于z轴,需要先把x,y,z赋值到一起,



