簡體   English   中英

Matplotlib-不規則的數據間隔

[英]Matplotlib — Irregular data intervals

如何創建具有x軸可縮放的圖? 此刻,圖平均間隔2、4、8、16、32...。

注意:data.txt文件具有所有原始y值(示例: 0.7690 0.7618 0.7762 0.7747 0.7783 0.7747 0.7152 0.6722 0.5151\\n ... )。 我平均所有列以獲得y值。

import matplotlib.pyplot as plt

file = open("data.txt", "r")
accs = file.readlines()
accs = [x.strip() for x in accs]

the_list = []
for i in range(len(accs[0].split())):
    the_list.append([])

for i in range(len(accs)):
    for k in range( len(accs[i].split() ) ):
        the_list[k].append( float(accs[i].split()[k] ))

avgs = []
for j in range(len(the_list)):
    avgs.append( sum(the_list[j]) / len(the_list[j]) )

x_vals = [2, 4, 8, 16, 32, 64, 128, 256, 512]
y_vals = [0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8]

plt.plot(avgs, "-b", label="batch size")
plt.xticks(range(len(avgs)), x_vals)
#plt.yticks(y_vals)
plt.ylabel('percentage')
plt.xlabel('batch size')
plt.legend(loc='lower right')


plt.show()

file.close()

您需要向繪圖函數提供x值和y值。

plt.plot(x,y, ...)

我假設在這種情況下

plt.plot(xvals,avgs, ...)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM