Matplotlib 线型不一致的破折号

Matplotlib linestyle inconsistent dashes

我正在使用 MPL 1.4.0 绘制一个简单的散点图。我想控制我正在绘制的图形上的破折号数量,因为目前即使我设置了线型,破折号彼此太靠近所以它看起来不像正确的虚线。

#load cdeax,cdeay,gsix,gsiy,reich all are arrays of shape (380,)
figfit = plt.figure(); axfit = figfit.gca() 

axfit.plot(cdeax,np.log(cdeay),'ko', alpha=.5); axfit.plot(gsix,np.log(gsiy), 'kx')
axfit.plot(cdeax,cdeafit,'k-'); axfit.plot(gsix,gsifit,'k:')
longevityregplot[1].plot(gsix,np.log(reich_l),'k-.')


#load cdeax,cdeay,gsix,gsiy,reich all are arrays of shape (380,)
figfit = plt.figure(); axfit = figfit.gca() 

axfit.plot(cdeax,np.log(cdeay),'ko', alpha=.5); axfit.plot(gsix,np.log(gsiy), 'kx')
axfit.plot(cdeax,cdeafit,'k-',dashes = [10,10]); axfit.plot(gsix,gsifit,'k:',dashes=[10,10])
longevityregplot[1].plot(gsix,np.log(reich_l),'k-.')

然而以上是我得到的。这些线不是统一的虚线,而是在末端以不同程度虚化,但无论我使用什么值作为破折号,破折号都不是统一的。

恐怕我真的不知道这里的问题是什么...有什么想法吗?

我在这里粘贴了我正在使用的数组:http://pastebin.com/rJ5Jjfmm 你应该能够 copy/paste 他们到你的 IDE 上面的代码到 运行.

干杯!

编辑:

仅绘制单线:

axfit.plot(cdeax,cdeafit,'k-',dashes = [10,10]); 

EDIT2:pastebin link 更改为包含所有数据

EDIT3:点密度沿 x 轴的直方图:

我认为@cphlewis 说的是正确的,你可能有一些 x 轴回溯。如果我对所有内容进行排序,我觉得没问题(因为我仍然没有在 pastebin 上看到适合的东西,所以我自己做了)

# import your data here
import math
figfit = plt.figure(); axfit = figfit.gca() 

cdea = zip(cdeax,cdeay)
cdea = np.array(sorted(cdea, key = lambda x: x[0]))

gsi = zip(gsix,gsiy)
gsi = np.array(sorted(gsi, key = lambda x: x[0]))

cdeafit2 = np.polyfit(cdea[:,0],cdea[:,1],1)
gsifit2 = np.polyfit([x[0] for x in gsi],[math.log(x[1]) for x in gsi],1)

cdeafit = [x*cdeafit2[0] + cdeafit2[1] for x in cdea[:,0]]

gsifit = [math.exp(y) for y in [x*gsifit2[0] + gsifit2[1] for x in gsi[:,0]]]

axfit.plot(cdea[:,0],cdea[:,1],'ko', alpha=.5); axfit.plot(gsi[:,0],gsi[:,1], 'kx')
axfit.plot(cdea[:,0],cdeafit,'k-',dashes = [10,10]); axfit.plot(gsi[:,0],gsifit,'k:',dashes=[10,10])
#longevityregplot[1].plot(gsix,np.log(reich_l),'k-.') # not sure what this is
axfit.set_yscale('log')
plt.show()