0

How would I create a plot that has an x-axis that is to scale? At the moment, the graph spaces 2, 4, 8, 16, 32, ... equally.

Note: The data.txt file has all the raw y-values (sample: 0.7690 0.7618 0.7762 0.7747 0.7783 0.7747 0.7152 0.6722 0.5151\n ...). I averaged all the columns to get the y values.

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()

1 Answer 1

1

You need to provide the xvalues as well as the yvalues to the plotting function.

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

I assume that in this case you want

plt.plot(xvals,avgs, ...)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.