cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Try the Materials Informatics Toolkit, which is designed to easily handle SMILES data. This and other helpful add-ins are available in the JMPĀ® Marketplace
Choose Language Hide Translation Bar
JohannesENS
Level III

Rectangle Graphic

Hello everybody,

is there an easy way in JMP to generate a graph with different rectangles (different sizes)? See an example attached.

With this graph I would like to give an overview of different materials and their corresponding shapes. 

 

Thanks in advance.

Johannes

3 ACCEPTED SOLUTIONS

Accepted Solutions
txnelson
Super User

Re: Rectangle Graphic

JMP has a complete set of graphic primitives' that can be used for creating things such as rectangles.  The Scripting Index details the functions available and gives examples of their use.

txnelson_0-1635935989392.png

txnelson_1-1635936060974.png

Here is the script from the Rect() function description.

Names Default To Here( 1 );
New Window( "Example",
	Graph Box(
		Pen Color( "Green" );
		Pen Size( 2 );
		Fill Color( "Red" );
		Rect( 15, 75, 65, 55, 1 );
		Rect( 10, 80, 70, 50 );
	)
);

 

Jim

View solution in original post

pmroz
Super User

Re: Rectangle Graphic

Lots of overlap in your data.  This code will do it; I set the rectangles to unfilled to show the overlap.

dt = data table("Rectangles");

// Set some constants
xmin = 0;
xmax = 4000;
ymin = 0;
ymax = 1500;
xres = 800;
yres = 500;

color_list  = {"Red", "Blue", "Green", "Orange", "Purple"};
filled_rect = 0;	// set to 1 for filled rectangles

heat_map_win = New Window( "Example Rectangles ",
	rect_gb = Graph Box(
		framesize( xres, yres ),
		xscale(xmin, xmax),
		yscale(ymin, ymax),
		for (i = 1, i <= nrows(dt), i++,
			xleft   = dt:x 1[i];
			xright  = dt:x 3[i];
			ybottom = dt:y 1[i];
			ytop    = dt:y 4[i];
			pcolor  = color_list[dt:material[i]];
			pen color(pcolor);
			fill color(pcolor);
			rect(xleft, ytop, xright, ybottom, filled_rect);
		),
	)
);

pmroz_0-1635947154958.png

 

View solution in original post

jthi
Super User

Re: Rectangle Graphic

I would definitely do this with Graph box but you can try to do something with Graph builder also. If I understood the data correctly you have couple of different versions per material. Based  on that I did some split/stack/formulas to get table like this:

jthi_1-1635948951890.png

With this table I then created Graph builder and used smoother with confidence of fit ON.

jthi_0-1635948890277.png

 

These two happened by accident and will work only because all rectangles have "line" in x = 0:

Bar chart + line char:

jthi_4-1635949449463.png

 

Also using line with fill below:

jthi_3-1635949422438.png

 

Datatable attached with tablescript.

 

Bonus image from same data:

jthi_2-1635949405258.png

 

-Jarmo

View solution in original post

8 REPLIES 8
jthi
Super User

Re: Rectangle Graphic

 What sort of data do you have? You can for example create custom shape files

-Jarmo
JohannesENS
Level III

Re: Rectangle Graphic

I attached a file with sample data. I do have coordinates for every corner of the rectangles.

txnelson
Super User

Re: Rectangle Graphic

JMP has a complete set of graphic primitives' that can be used for creating things such as rectangles.  The Scripting Index details the functions available and gives examples of their use.

txnelson_0-1635935989392.png

txnelson_1-1635936060974.png

Here is the script from the Rect() function description.

Names Default To Here( 1 );
New Window( "Example",
	Graph Box(
		Pen Color( "Green" );
		Pen Size( 2 );
		Fill Color( "Red" );
		Rect( 15, 75, 65, 55, 1 );
		Rect( 10, 80, 70, 50 );
	)
);

 

Jim
JohannesENS
Level III

Re: Rectangle Graphic

Thank you!

Craige_Hales
Super User

Re: Rectangle Graphic

Also look at the transparency command if you have issues with which one is in front.

 

both rectangles are drawn with 50% alphaboth rectangles are drawn with 50% alpha

Craige
pmroz
Super User

Re: Rectangle Graphic

Lots of overlap in your data.  This code will do it; I set the rectangles to unfilled to show the overlap.

dt = data table("Rectangles");

// Set some constants
xmin = 0;
xmax = 4000;
ymin = 0;
ymax = 1500;
xres = 800;
yres = 500;

color_list  = {"Red", "Blue", "Green", "Orange", "Purple"};
filled_rect = 0;	// set to 1 for filled rectangles

heat_map_win = New Window( "Example Rectangles ",
	rect_gb = Graph Box(
		framesize( xres, yres ),
		xscale(xmin, xmax),
		yscale(ymin, ymax),
		for (i = 1, i <= nrows(dt), i++,
			xleft   = dt:x 1[i];
			xright  = dt:x 3[i];
			ybottom = dt:y 1[i];
			ytop    = dt:y 4[i];
			pcolor  = color_list[dt:material[i]];
			pen color(pcolor);
			fill color(pcolor);
			rect(xleft, ytop, xright, ybottom, filled_rect);
		),
	)
);

pmroz_0-1635947154958.png

 

LargeElk892
Level II

Re: Rectangle Graphic

Thanks for the code. Working well for me.

Now I'd like to split the graphs by another key column. E.g. graph 1 will have the  rectangles for parameter A, graph 2 will have the  rectangles for parameter B, etc.

I'm struggling to use a Where or By clause here.

I would need to have all the graphs displayed vertically and save it as a jpg.

Thank you

jthi
Super User

Re: Rectangle Graphic

I would definitely do this with Graph box but you can try to do something with Graph builder also. If I understood the data correctly you have couple of different versions per material. Based  on that I did some split/stack/formulas to get table like this:

jthi_1-1635948951890.png

With this table I then created Graph builder and used smoother with confidence of fit ON.

jthi_0-1635948890277.png

 

These two happened by accident and will work only because all rectangles have "line" in x = 0:

Bar chart + line char:

jthi_4-1635949449463.png

 

Also using line with fill below:

jthi_3-1635949422438.png

 

Datatable attached with tablescript.

 

Bonus image from same data:

jthi_2-1635949405258.png

 

-Jarmo