Sjayan Sjayan - 27 days ago 8
Python Question

Pandas plotting pyplot not showing graph

I have been trying to plot weekly stock data using a

for
loop. My code is as follows, but my graph is incorrect.

for x in range(0, max(stock['week']) + 1):
print(x)
df = stock[stock.week == x]
plt.plot(x = df['new_date'], y = df['Low'], linewidth=5, color = [0, 0, 1])
print(df)
# df.plot(x = df['new_date'], y=df['Low'])
plt.savefig('weekGraph/' + str(x) + '.png')


My graph look like this I am getting a graph like this

I am new to python. Where is the mistake in my code?

Answer Source

For once replace this line plt.plot(x = df['new_date'], y = df['Low'], linewidth=5, color = [0, 0, 1])

with:

plt.plot(df['new_date'], df['Low'], linewidth=5, color = [0, 0, 1]) and see if it works. Everything else looks quite ok from this side.