バージョン: 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()