<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: R-plot though JSL/JMP in Discussions</title>
    <link>https://community.jmp.com/t5/Discussions/R-plot-though-JSL-JMP/m-p/804938#M98278</link>
    <description>&lt;P&gt;Hi Paul Thank you for your answer. I am trying to repeat the same process just for Python instead of R.&lt;BR /&gt;&lt;BR /&gt;And the JSL keep loading the last defined plot from Python instead of plotting the correct figure.&lt;BR /&gt;&lt;BR /&gt;The&amp;nbsp;plt.show(plt.figure(plot1)) works in Python but when I use the code below in JSL:&lt;BR /&gt;plot1 = Picture Box(Python Get Graphics("png","plt.show(plt.figure(plot1)"));&lt;/P&gt;&lt;P&gt;Then JSL keep takeing the last defined plot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have a suggestion of what I wo wrong?&lt;/P&gt;</description>
    <pubDate>Thu, 10 Oct 2024 20:55:24 GMT</pubDate>
    <dc:creator>NormalDistSigma</dc:creator>
    <dc:date>2024-10-10T20:55:24Z</dc:date>
    <item>
      <title>R-plot though JSL/JMP</title>
      <link>https://community.jmp.com/t5/Discussions/R-plot-though-JSL-JMP/m-p/803149#M97995</link>
      <description>&lt;P&gt;I have this script as seen below where I calculate some simple in R, and where I want to see some plots in JSL. I cannot get JSL to show the two plots. When I run the code below it close plot1 and only show plot two. I have tried using what is descirbed here ( &lt;A href="https://community.jmp.com/t5/JMPer-Cable/Getting-started-with-the-JMP-to-R-Interface/ba-p/43920" target="_blank"&gt;https://community.jmp.com/t5/JMPer-Cable/Getting-started-with-the-JMP-to-R-Interface/ba-p/43920&amp;nbsp;&lt;/A&gt;) but I cannot get it to work. It might be a simple command but I am pretty new to JSL. I hope you can help. FYI I use JMP 17.2&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;Names Default To Here(1);&lt;/P&gt;&lt;P&gt;Include("Dialog_script.jsl"); // Load the dialog to get selected X and Y columns&lt;BR /&gt;dt = Current Data Table(); // Get the current data table&lt;/P&gt;&lt;P&gt;// Get the selected X and Y columns from the data table&lt;BR /&gt;xCol = Column(dt, xColName[1]);&lt;BR /&gt;yCol = Column(dt, yColName[1]);&lt;/P&gt;&lt;P&gt;// Check if columns exist&lt;BR /&gt;If(xCol == Empty() | yCol == Empty(),&lt;BR /&gt;Throw("Error: The selected columns do not exist in the data table.");&lt;BR /&gt;);&lt;/P&gt;&lt;P&gt;// Extract the values from xCol and yCol&lt;BR /&gt;xValues = xCol &amp;lt;&amp;lt; Get Values; // Get the values of xCol&lt;BR /&gt;yValues = yCol &amp;lt;&amp;lt; Get Values; // Get the values of yCol&lt;/P&gt;&lt;P&gt;// Show the values being sent to R (for debugging)&lt;BR /&gt;Show(xValues);&lt;BR /&gt;Show(yValues);&lt;/P&gt;&lt;P&gt;// Initialize the R connection&lt;BR /&gt;R Init();&lt;/P&gt;&lt;P&gt;// Send the values of xCol and yCol to R as numeric vectors&lt;BR /&gt;R Send( xValues );&lt;BR /&gt;R Send( yValues );&lt;/P&gt;&lt;P&gt;// Execute the external R script&lt;BR /&gt;R Submit File( "C:/Users/NDS/Data_Ana.R" );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// Retrieve the plot&amp;nbsp;&lt;BR /&gt;&amp;nbsp;R submit( "print(plot1)" );&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;R submit( "print(plot2)" );&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;// Terminate the R connection&lt;BR /&gt;//R Term();&lt;/P&gt;</description>
      <pubDate>Wed, 02 Oct 2024 07:04:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/R-plot-though-JSL-JMP/m-p/803149#M97995</guid>
      <dc:creator>NormalDistSigma</dc:creator>
      <dc:date>2024-10-02T07:04:42Z</dc:date>
    </item>
    <item>
      <title>Re: R-plot though JSL/JMP</title>
      <link>https://community.jmp.com/t5/Discussions/R-plot-though-JSL-JMP/m-p/803263#M98006</link>
      <description>&lt;P&gt;I believe what you are seeing is plot 2 immediately replaces plot 1 as you have no intervening Wait() or code to capture the image or display the image in a new JMP window. &amp;nbsp;In running R's plot() you are getting an R window not a JMP window, so when you run the second plot command it's overwriting the first plot. &amp;nbsp;From the link you referenced, see the section on R Get Graphics().&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Try something like&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;...
R Submit("print(plot1)");
New Window("Plot 1", Picture Box( R Get Graphics(png) ) );
R Submit("print(plot2)");
New Window("Plot 2", Picture Box( R Get Graphics(png) ) );
...&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;Have you looked at the examples in JMP's scripting index, that is located under the Help menu. &amp;nbsp;The script below comes from the Scripting index 'R Get Graphics'&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;Names Default To Here( 1 );
R Init();
R Submit( "plot(1:10)" );
plot = R Get Graphics( png );
New Window( "Plot", Picture Box( plot ) );
R Term();&lt;/CODE&gt;&lt;/PRE&gt;</description>
      <pubDate>Wed, 02 Oct 2024 14:22:42 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/R-plot-though-JSL-JMP/m-p/803263#M98006</guid>
      <dc:creator>Paul_Nelson</dc:creator>
      <dc:date>2024-10-02T14:22:42Z</dc:date>
    </item>
    <item>
      <title>Re: R-plot though JSL/JMP</title>
      <link>https://community.jmp.com/t5/Discussions/R-plot-though-JSL-JMP/m-p/804938#M98278</link>
      <description>&lt;P&gt;Hi Paul Thank you for your answer. I am trying to repeat the same process just for Python instead of R.&lt;BR /&gt;&lt;BR /&gt;And the JSL keep loading the last defined plot from Python instead of plotting the correct figure.&lt;BR /&gt;&lt;BR /&gt;The&amp;nbsp;plt.show(plt.figure(plot1)) works in Python but when I use the code below in JSL:&lt;BR /&gt;plot1 = Picture Box(Python Get Graphics("png","plt.show(plt.figure(plot1)"));&lt;/P&gt;&lt;P&gt;Then JSL keep takeing the last defined plot.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Do you have a suggestion of what I wo wrong?&lt;/P&gt;</description>
      <pubDate>Thu, 10 Oct 2024 20:55:24 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/R-plot-though-JSL-JMP/m-p/804938#M98278</guid>
      <dc:creator>NormalDistSigma</dc:creator>
      <dc:date>2024-10-10T20:55:24Z</dc:date>
    </item>
    <item>
      <title>Re: R-plot though JSL/JMP</title>
      <link>https://community.jmp.com/t5/Discussions/R-plot-though-JSL-JMP/m-p/805156#M98321</link>
      <description>&lt;P&gt;First, from the documentation in the Scripting Index, &amp;nbsp;Syntax: image = Python Get Graphics( format );&lt;/P&gt;
&lt;P&gt;There is no second parameter. &amp;nbsp;The scripting index description states:&amp;nbsp;&lt;EM&gt;Returns the last graphics object written to the Python graph display window in a graphics format specified by the format parameter.&lt;/EM&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Second,&amp;nbsp;&lt;SPAN&gt;You must be using JMP prior to JMP 18.&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT face="inherit"&gt;Python Get Graphics(png); was deprecated in 18, and already removed from JMP 19 &lt;/FONT&gt;development&lt;FONT face="inherit"&gt;&amp;nbsp;builds. &amp;nbsp;In JMP 18 it does not return a value, but instead raises an Alert dialog. The appropriate way which will across all versions of JMP, is to have&amp;nbsp;&lt;/FONT&gt;the Python code save the image to a file. Then Open() the file and hand that off off to a JSL Picture Box(). &amp;nbsp;JMP 18's scripting index for Python Get Graphics() gives a complete example of the workaround. &amp;nbsp;&lt;/P&gt;
&lt;P&gt;Instead of doing a plt.show()&lt;/P&gt;
&lt;P&gt;you should do:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;# save image to location of your choosing 
plt.savefig( jmp.TEMP + 'get_graphics_img.png') # JMP 18+

# or ... savefig( '/tmp/get_graphics_img.png')  before JMP 18 (macOS).&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;Then from JSL: &amp;nbsp;&lt;EM&gt;or via jmp.run_jsl(''' ... '''') from Python&amp;nbsp;&lt;/EM&gt;&lt;/P&gt;
&lt;PRE&gt;&lt;CODE class=" language-jsl"&gt;// plot = Python Get Graphics( png );       // DEPRECATED
pngJMP = New Window( "Plot", Picture Box( Open( "$TEMP/get_graphics_img.png", png ) ) );
Python Submit( "plt.close()" );
rc = Delete File( "$TEMP/get_graphics_img.png" );&lt;/CODE&gt;&lt;/PRE&gt;
&lt;P&gt;There is another issue. &amp;nbsp;Especially if running on the Mac, matplotlib and JMP fight for control over the window event loop if matplotlib is brought up interactively. &amp;nbsp;You can get an exit of JMP by closing the last matplotlib window visible on screen. &amp;nbsp;This depends on the matplotlib backend, but it's especially finicky on macOS.&lt;/P&gt;</description>
      <pubDate>Fri, 11 Oct 2024 20:47:31 GMT</pubDate>
      <guid>https://community.jmp.com/t5/Discussions/R-plot-though-JSL-JMP/m-p/805156#M98321</guid>
      <dc:creator>Paul_Nelson</dc:creator>
      <dc:date>2024-10-11T20:47:31Z</dc:date>
    </item>
  </channel>
</rss>

