0

When I run this Python program the x and y axes scale adjusts as more data gets plotted. Is it possible to set a scale to which the chart will be created to and have it not change during excution? I had tried plt.xlim(0, 30) and plt.ylim(0, 1050) but it made no difference.

import numpy as np
from itertools import count
import pandas as pd
import matplotlib.pyplot as plt
from matplotlib.animation import FuncAnimation

plt.style.use('fivethirtyeight')

data = pd.read_csv('csv_data.csv')
x_vals = []
y_vals1 = []
y_vals2 = []

index = count()


def animate(i):
    x = data['x_value']
    y1 = data['total_1']
    y2 = data['total_2']
    x_vals = x[0:i]
    y_vals1 = y1[0:i]
    y_vals2 = y2[0:i]

    plt.cla()
    plt.plot(x_vals, y_vals1, label='Channel 1')
    plt.plot(x_vals, y_vals2, label='Channel 2')

    plt.legend(loc='upper left')

    plt.tight_layout()


ani = FuncAnimation(plt.gcf(), animate, frames=len(data.index) -1, interval=100, repeat = False)

plt.show()
runnerpaul
  • 5,942
  • 8
  • 49
  • 118

1 Answers1

0

Add the following lines after plt.cla:

plt.xlim(0, 27)
plt.ylim(900, 1050)
runnerpaul
  • 5,942
  • 8
  • 49
  • 118