2016-12-16 115 views
0

我使用matplotlib做一個組件的組件加上殘餘(CCPR)情節(=部分殘差圖)的非取向Matplotlib:所述點的上曲線圖

此腳本:

fig, ax = plt.subplots(figsize=(5, 5)) 
fig = sm.graphics.plot_ccpr(lm_full, 'diag[T.sz]', ax=ax) 
plt.close 

得出:

Bad Plot

如何修改我的腳本要達到這樣的

Good plot

我不希望我的點對齊。在這兩種情況下,x軸的變量都是虛擬變量(生病與健康控制)。

這看似愚蠢的,但我不知道該怎麼表達我想要的東西:它是與圖像更加容易。

回答

1

這聽起來像你想添加一些抖動添加到X值,如:

import numpy as np 

# get x and y coordinates from the axes 
coords = ax.collections[0].get_offsets() 

# add small random number to each x coordinate 
coords[:,0] = coords[:,0] + np.random.rand(coords.shape[0]) * 0.01 

# move the points to the new coordinates 
ax.collections[0].set_offsets(coords) 
+0

謝謝!我很抱歉,但我不understant如何實現,在我的代碼... – salim

+0

行後來看,它'圖= sm.graphics.plot_ccpr(lm_full,「診斷[T.sz]」,AX = A)' – Michael

+0

我試過但ax.collections [0]返回「列表索引超出範圍」 – salim