def jitt(vote):
n = len (vote)
return np.where(
vote < 0.1 ,
rng.uniform(0.01 , 0.04 , n),
np.where(vote > 0.9 , rng.uniform(0.96 , 0.99 , n), vote),
)
j_v86 = jitt(congress["v86" ])
j_v88 = jitt(congress["v88" ])
fig, ax = plt.subplots()
ax.scatter(
j_v86[congress["inc88" ] == 0 ],
j_v88[congress["inc88" ] == 0 ],
marker= "*" ,
c= "black" ,
s= 20 ,
)
ax.scatter(
j_v86[congress["inc88" ] == 1 ],
j_v88[congress["inc88" ] == 1 ],
marker= "x" ,
c= "black" ,
s= 20 ,
)
ax.scatter(
j_v86[congress["inc88" ] == - 1 ],
j_v88[congress["inc88" ] == - 1 ],
marker= "o" ,
c= "black" ,
s= 20 ,
)
ax.plot([0 , 1 ], [0 , 1 ], color= "gray" , linestyle= "--" )
ax.set_title("Raw data" )
ax.set_xlabel("Democratic vote share in 1986" )
ax.set_ylabel("Democratic vote share in 1988" )