버전: JMP 18.0.1
아래에 2개의 Python 스크립트를 포함했습니다. 둘 다 함수 안에 그림을 생성하고 이미지로 저장합니다. Python Get()을 사용하여 이미지 파일을 직접 호출하면 jmp.run_jsl을 사용하여 차트가 있는 창을 열 수 있습니다. 그러나 동일한 작업을 수행했지만 어떤 이유로 jmp.run_jsl을 main() 함수 내에 래핑하면 Python Get()이 작동하지 않고 파일 위치에 대한 문자열을 새 그림 창에 전달할 수 없습니다. 어떤 도움이라도 대단히 감사하겠습니다.
안녕!
변수 범위와 관련이 있다고 생각합니다. testcode_v1.txt에서 플롯 변수는 main() 함수 내부에 정의되는 반면, testcode_v2.txt에서는 플롯 변수가 제한 범위 외부에서 정의되어 전역으로 만듭니다. 분명히 일부 내부 범위 내에서 JSL 스크립트를 실행하더라도 해당 특정 범위에 정의된 변수에 액세스할 수 있다는 의미는 아닙니다.
이에 대한 최소한의 노력 해결 방법은 플롯 변수를 전역으로 정의하는 것입니다. 빨간색으로 강조된 부분을 보세요.
import matplotlib.pyplot as plt
import jmp
plot = None
def show_plot():
fig, ax = plt.subplots()
fruits = ['apple', 'blueberry', 'cherry', 'orange']
counts = [40, 100, 30, 55]
bar_labels = ['red', 'blue', '_red', 'orange']
bar_colors = ['tab:red', 'tab:blue', 'tab:red', 'tab:orange']
ax.bar(fruits, counts, label=bar_labels, color=bar_colors)
ax.set_ylabel('fruit supply')
ax.set_title('Fruit supply by kind and color')
ax.legend(title='Fruit color')
plot = "your_file_path.png"
plt.savefig(plot,format='png')
return plot
def main():
global plot
plot = show_plot()
print(plot)
jmp.run_jsl('''
model = Python Get (plot);
show (model);
plot_model = Open(model, png);
pngJMP = New Window( "Test Model Representation", Picture Box( plot_model ),
<< bring window to front;
);
Python Submit( "plt.close()" );
''')
if __name__ == "__main__":
main()