1

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:

enter image description here

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.

Vorac
  • 8,726
  • 11
  • 58
  • 101
  • 1
    Possibly related: [dynamically update plot - array length not known a priori](http://stackoverflow.com/questions/15930529/python-matplotlib-dynamically-update-plot-array-length-not-known-a-priori) – Schorsch Jan 15 '16 at 15:34

0 Answers0