cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
ziboltis
Level I

matplotlib on JMP graph builder

Hi I'm trying to combine matplotlib and JMP graph builder, but I don't know if it is possible. I want to plot a particular graph that I only could plot on matplotlib; but I want to take the advantages about the JMP graph builder interface, like data filtering. It is possible to show a matplotlib plot over the JMP graph builder interface? Thanks in advance

4 REPLIES 4
txnelson
Super User

Re: matplotlib on JMP graph builder

A script could handle using a Data Filter, which triggers the matplotlib code and recreates the graph based upon the filtered data.  But I do not know of anyway to integrate Graph Builder with matplotlib.

Jim
peng_liu
Staff

Re: matplotlib on JMP graph builder

I might misunderstand the desired outcome, but sounds like that you only need a data filter and a plot, not the drag-n-drop interactivity in Graph Builder (GB) and the complex graph layout within GB.

If so, I believe that you at least need following ingredients:

  1. JSL function "Make Filter Change Handler", so you can get subsets of data based on the state of the data filter. See example for "Make Filter Change Handler" in Scripting Index.
  2. JSL function "Python Get Graphics", so you can get plot back from python. See example for "Python Get Graphics" in Scripting Index.
  3. A "Data Filter Context Box" display box to hold both the filter and your plot, and possibly other analysis together.

Here is a small example which puts the elements together.

 

dt = Open( "$SAMPLE_DATA/Cities.jmp" );
New Window( "Shared Local Filter",
	Data Filter Context Box(
		H List Box(
			filter = (dt << Data Filter( Local, Add Filter( columns( :Region ) ) )),
			pb = Picture Box()
		)
	)
);
f = Function( {nrows}, 
	rows = filter << get filtered rows;
	xx = dt:X[rows];
	yy = dt:Y[rows];
	Python Init();
	Python Send(xx);
	Python Send(yy);
	ml = Python Submit(
		"\[
import matplotlib.pyplot as plt
plt.scatter(xx,yy)
plt.xlabel('X')
plt.ylabel('Y')
plt.show(block=False)
		]\"
	);
	plot = Python Get Graphics( png );
	pb << set image(plot);
	Python Submit( "plt.close()" );
	Python Term();
);
rs = filter << Make Filter Change Handler( f );

Pay attention to Python's indentation rule. E.g. all strings in Python Submit must stick they fronts at the beginning of the lines.

Here are a couple of screenshots of the product.

peng_liu_0-1637373613101.png

 

peng_liu_1-1637373625672.png

 

 

 

Craige_Hales
Super User

Re: matplotlib on JMP graph builder

Amazing great example!

If you use this example, be prepared to wait for Python to load after the first click; my slow machine might take 10-30 seconds. Once loaded, it is fast enough on subsequent clicks.

Craige
txnelson
Super User

Re: matplotlib on JMP graph builder

This example needs to be added to the JMP Cookbook 

Jim