1

I use Embedding Python in C++, in my program, I have to run the python module many times. Unfortunately, the plt.show() only gets the figure one time, the others get the null figure

import matplotlib.pyplot as plt  
import numpy as np
from matplotlib.patches import Ellipse, Circle
import time
def show(x,y,x1,y1):
    fig=plt.figure()
    fig.gca().invert_yaxis()
    ax1 = fig.add_subplot(111)
    cir1 = Circle(xy = (x1, y1), radius=0.02, alpha=0.5)
    ax1.add_patch(cir1)
    print len(x)
    print x1
    ax1.set_title('Scatter Plot')
    plt.xlabel('X')
    plt.ylabel('Y')  
    ax1.scatter(x,y,c = 'r',marker = 'o')
    plt.ion()
    plt.show()
    time.sleep(1)
    plt.close()
    return 'ok'

enter image description here

1
  • Try this, maybe you need to call fig.show() first, otherwise it just dies. Commented Feb 24, 2017 at 13:19

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.