Elliot L
Elliot L

Reputation: 19

I am having trouble graphing data in matplotlib

I have written this but its not displaying correctly as a line graph. What am I doing wrong? Normalpwr are to all my x-coordinates corresponding with axfuelline as my y-coordinates. I appreciate any help/tips!

normalpwr = [0.232, 0.397, 0.562, 0.681, 0.754, 0.797, 0.83, 0.843, 0.855, 0.867, 0.883, 0.9, 0.921, 0.943, 0.967, 0.992, 1.017, 1.043, 1.068, 1.092, 1.115, 1.137, 1.157, 1.176, 1.193, 1.209, 1.224, 1.236, 1.249, 1.261, 1.272, 1.283, 1.292, 1.289, 1.274, 1.234, 1.174, 1.048, 0.86, 0.61, 0.361]
axfuelline = [0.000, 0.025, 0.050, 0.075, 0.100, 0.125, 0.150, 0.175, 0.2, 0.225, 0.25, 0.275, 0.3, 0.325, 0.35, 0.375, 0.4, 0.425, 0.450, 0.475, 0.5, 0.525, 0.550, 0.575, 0.6, 0.625, 0.650, 0.675, 0.7, 0.725, 0.750, 0.8, 0.825, 0.85, 0.875, 0.9, 0.925, 0.950, 0.975, 1]
x = normalpwr[i]
y = axfuelline[i]
plt.plot(x,y, 'ro')
plt.show()

Upvotes: 0

Views: 29

Answers (1)

Rein K.
Rein K.

Reputation: 141

Firstly, your lists are not of the same size. normalpwr is of length 41, while axfuelline is of length 40.

Beside this point, you want to plot a line graph. You are on the right way, but you should not add [i] when defining x and y, since this indicates that you want to use an index (which tells the code to use one part of the list).

Rather, you want to use:

    x = normalpwr
    y = axfuelline
    plt.plot(x,y)
    plt.show()

Note that I also removed 'ro' from the plot function, because this plots the points as red dots, rather than a line.

Upvotes: 1

Related Questions