问题描述:

I created live graph for analysis data.I want to draw bottom sides of line with fill command.But when I tried to write that code and similar things, always error popup.By the way I will modify graph thats why I added so many import things.

ax1.fill_between(x, y, 0, alpha=0.3) --> output warn me because of this row.I tried x or xs versions but couldnt work how to define them.

Here my codes.

import matplotlib.pyplot as plt

import matplotlib.animation as animation

from matplotlib import style

import matplotlib.dates as mdates

import numpy as np

import urllib

import datetime as dt

style.use('fivethirtyeight')

fig = plt.figure()

ax1 = fig.add_subplot(1,1,1)

def animate(i):

graph_data=open('api2.txt','r').read()

lines = graph_data.split('\n')

xs = []

ys = []

for line in lines:

if len(line) > 1:

x, y = line.split(',')

xs.append(x)

ys.append(y)

ax1.clear()

ax1.plot(xs, ys)

ax1.fill_between(x, y, 0, alpha=0.3)

ani = animation.FuncAnimation(fig, animate, interval=1000)

plt.show()

my sample api2 data:

1,4

2,5

3,7

4,9

5,2

6,8

7,1

8,3

9,1

10,4

15,26

Error:

 ax1.fill_between(x, y, 0, alpha=0.3)

NameError: name 'x' is not defined

>>>

相关阅读:
Top