Issue
I tried to make graph with matplotlib, and my graph should start from 1 not 0, But I don't know how to do. I can do this by writing all figures in x_coords and y_coords, but I want to know the code I can use while I use f = open()
. Sorry that I'm not fluent in English
import matplotlib.pyplot as plt
import numpy as np
avg_prices = []
labels = (i for i in range(1, 53))
f = open('C:/1994_Weekly_Gas_Averages.txt', 'r')
for line in f:
avg_prices.append(float(line))
plt.plot(avg_prices, 'o--', label=labels)
plt.title('1994 Weekly Gas Prices')
plt.xlabel('Weeks')
plt.ylabel('Average prices')
plt.grid()
plt.xticks(np.arange(0, 60, 10))
plt.yticks(np.arange(1, 1.17, 0.025))
plt.show()
Solution
Just include the corresponding x coordinate in before the y coordinate.
x = list(range(1,53))
plt.plot(x, avg_prices)
Answered By - Jacob
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.