This is my class:
import matplotlib.pyplot as plt
import collections as col
import numpy as np
class Graph(object):
"""Single 2-D dynamic plot. The axes must be same length and
have both minimum and maximum possible values.
"""
def __init__(self, window, subplot_num, x_axis, y_axis):
ax = window.add_subplot(subplot_num)
self.y, = ax.plot(x_axis, # Obtain handle to y axis.
y_axis,
marker='^'
)
self.y_data = col.deque(y_axis, # Circular buffer.
maxlen=len(y_axis)
)
# Make plot prettier
plt.grid(True)
plt.tight_layout()
def add_datapoint(self, y):
self.y_data.appendleft(y) # Remember - circular buffer.
self.y.set_ydata(self.y_data)
I am passing to x_axis range(60)
to set the static horizontal axis. y_axis is getting range(10, 60)
in order to set it's range.
From then on, I listen to stdin and add a new point each second.
The problem is, that the inital graph is hidious:
I want to remove the initial diagonal line. I tried initializing y_axis with NaNs and calling ax.set_yrange()
, but that doesn't do what I am opting for. I also tried not passing y values, but mpl.plot wants x and y axes of equal length.
How can I remove the initial diagonal line? I am ok both with manually setting y range or the graph resizing dynamically as new data arrives.