gpt4 book ai didi

python - Matplotlib 线型不一致的破折号

转载 作者:行者123 更新时间:2023-11-28 18:38:40 24 4
gpt4 key购买 nike

我正在使用 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-.')

Why I want to control dashes


#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-.')

What I end up the 1st time

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

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

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

干杯!

编辑:

仅绘制单线:

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

enter image description here

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

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

enter image description here

最佳答案

我认为@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

关于python - Matplotlib 线型不一致的破折号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29762988/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com