Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
128 views
in Technique[技术] by (71.8m points)

python - Issue need line plot to start from first data point

I have the following code, its working fine but I am struggling with two issues first the line graph is not started from the first data point and second issue is first data point is not properly displayed on the grah.

 x=[1, 2, 3, 4, 5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25]
 y=[12.97,26.02,71.73,23.86,31.09,44.73,17.7,23.86,36.36,36.82, 36.30,14.73,23.34,33.10,     
   32.23,32.73,13.46,18.92,19.42,19.63,19.50,12.65,14.99,56.32,22.97]
 z=[12.78,28.25,69.35,19.33, 32.53,49.81,15.41,28.95,45.16,40.05,37.24,13.39,23.52,37.58,42.42,  
   51.19,13.31,22.74,23.78,20.51,20.86,12.77,15.92,55.31,23.42]
 j=[14.04,31.53,99.84,23.28,44.08,81.37,20.58,44.58,57.73,55.69,50.77,15.79,     
   28.62,48.27,55.02,58.45,14.26,25.88,26.26,28.67,28.95,14.89,16.65,55.80, 26.345]
 k= [51.45,51.71,115.48,24.67,53.3,109.31,50.54,46.83,77.58,96.59,30.92,49.79,72.08,92.05,72.35,
    18.11,38.37,57.46,36.99,28.15,16.73,15.74,77.92,34.97]
 l=[0.589,12.545,12.545,3.137,6.273,6.273,1.569,3.137,3.137,3.137,3.137,0.785,1.569,1.569,1.569,     
   1.569,0.393,0.393,0.393,0.393,0.393,0.09,0.09,0.17,0.17]
 plt.plot(y, marker='d',label='0%',linestyle = 'None',color='royalblue')
 plt.plot(z, marker='s',label='30%',linestyle = 'None',color='darkorange')
 plt.plot(j,marker='v',label='60%',linestyle='None',color='grey')
 plt.plot(k,marker='x',label='90%',linestyle='None',color='red')
 plt.ylim(0, 150)
 r = range(len(x))
 plt.xticks(rotation=90)
 ax2 = plt.twinx()
 plt.plot(x, l, color='grey',marker='o')
 plt.ylim(0, 16)
 plt.xlim(0, 25)
 plt.xticks(r,x,rotation=90)
question from:https://stackoverflow.com/questions/66063310/issue-need-line-plot-to-start-from-first-data-point

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

change the following line:

plt.plot(x, l, color='grey',marker='o')

to

plt.plot(range(25), l, color='grey', marker='o')

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...