Initialize the graph in matplotlib and then insert elements

Asked

Viewed 131 times

0

Hello. Is there any way I can first open a chart with matplotlib and, after opened, perform some operations? Ex: open graph and then plot a straight line, then another, so on.

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

plt.io()

and then

plt.show()

I did this, but the graph hangs in such a way that it doesn’t even respond. My goal here is to initialize the blank graph and then plot some 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 startPlot() once and printCurve() several times. I want to call plt.show() first of all, but if I do this or make plt.show(break=True), don’t plot anything else after that.

1 answer

0

From what I found, you must use

plt.ion()

along with

plt.draw()

just like this example or this question in the OS.

Unfortunately I can’t test because I’m in a python text mode for now. I do an update later.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.