1

I'm trying to plot a chart using PyPlot.plot.

First want to plot few arrays and save a figure.

Then I want to plot a similar chart (keep the same x and y labels and range values), but with different array

How do I go about doing this without having to define the axes and labels again? cla(), clf() etc wipes out the axis

import numpy as np
import matplotlib.pyplot as plt

def plot_me():
    n1 = np.array([30,40,500])
    n2 = np.array([300,400,500])
    n3 = np.array([1000, 1400, 5000])

    plt.plot(n1, label = 'Trial 1')
    plt.plot(n2, label = 'Trial 2')
    plt.plot(n3, label = 'Trial 3')

    plt.title('First set of trials')
    plt.legend(loc='lower right')

    plt.xlabel('X-axix')
    plt.ylabel('Y-axis')
    plt.axis([0, 3, 0, 5000])

    plt.savefig("c:\\images\\1.png")

    n4 = np.array([400, 450, 475])

    #I want to just clear the data from n1, n2, n3
    # but keep the axes and labels

    plt.plot(n4, label='New Trial 1')

    plt.title('Second set of trials')
    plt.legend(loc='lower right')

    plt.savefig("c:\\images\\2.png")
Stubborn
  • 290
  • 2
  • 17
  • Possible duplicate of [How to update a plot in matplotlib?](https://stackoverflow.com/questions/4098131/how-to-update-a-plot-in-matplotlib) – Roope Aug 31 '19 at 23:20

0 Answers0