Initialize the graph in the matplotlib and then insert elements

0

Hello. Is there any way I can first open a chart with matplotlib and, after open, perform some operations? Eg open chart and then plot one line, then another, and so on.

I know there are some topics in the English stackoverflow about this, and the solution that comes closest to my problem says to use

  

plt.io ()

, and then

  

plt.show ()

I did this, but the chart hangs in such a way that it does not even respond. My goal here is to initialize the blank chart and then draw some straight lines.

My code so far:

   def startPlot():
    plt.title('Adaline')
    plt.axis([-0.2, 1.2, -0.1, 1.4])
    plt.grid()
    #plots the dots
    plt.plot([0, 0, 1, 1], [0, 1, 0, 1], 'ro')
    plt.draw()



def printCurve(weights, bias):
    plt.title('Adaline')
    t = np.arange(0.0, 1.0, 0.001)
    f = (-weights[1] * t  - bias)/(weights[0])
    #plots the curve
    plt.plot(t, f, 'k')
    plt.draw()

I call the startPlot () and printCurve () several times. I want to call plt.show () first, but if I do this or do plt.show (break = True), it will not plot anything else after that.

    
asked by anonymous 23.11.2017 / 21:02

1 answer

0

From what I've found, you should use

plt.ion()

along with

plt.draw()

such as this example or this question in the SO .

Unfortunately I can not test because I'm in a python text mode for now. I'll post an update later.

    
24.11.2017 / 14:28