Matplotlib线型不一致的短划线

2024-09-27 21:31:49 发布

您现在位置:Python中文网/ 问答频道 /正文

我只是用mpl1.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-.')

Why I want to control dashes


^{pr2}$

What I end up the 1st time

不过,以上是我得到的。不是一条统一的虚线,这些线在端点处以不同程度的虚线出现,但是不管我使用什么样的虚线值,虚线永远都不是统一的。在

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

我已经粘贴了我在这里使用的数组:http://pastebin.com/rJ5Jjfmm 您应该能够将它们复制/粘贴到您的IDE中,以便上面的代码运行。在

干杯!在

编辑:

只需绘制一条直线:

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

enter image description here

编辑2:pastebin链接已更改为包括所有数据

编辑3:沿x轴的点密度直方图:

enter image description here


Tags: log编辑plot粘贴np绘制虚线gsiy
1条回答
网友
1楼 · 发布于 2024-09-27 21:31:49

我想@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()

demo plot

fits only

相关问题 更多 >

    热门问题