Subscribe Bookmark RSS Feed

saving graphs as PNG or JPEG

vishwasanj

Frequent Contributor

Joined:

Dec 27, 2016

Hi,

 

I have made a script which lets the user select an excel file, process it , add or formulates columsn to it, opens graph builder and plots it with local data filter.

My question is:

 

1. How do I save graphs choosing the local data filter option using the script? For example, I have 2 local data filters, say Trimset(10, 100, 101, 110, 111, 1000, 11111) and formula(yes or no) and I need to plot graphs like (All trimset values with formula NO) and (Each of the trimset values with formula YES) .. so a total of 8 graphs.

2. In my graph, I want the statement beneath the graph "Where Trimset is .... and formula is NO " to be included.

3. Save graphs in a folder in png or jpeg files

4.JMP data table and graph builder tables exits without saving.

5. how to make an addin feature to make it a single click operation because I need to do this for 100 or more files?

 

I have been reading all the discussions but I am not able to get the right answer. I really appreciate your help.

Thank you

 

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales

Staff

Joined:

Mar 21, 2013

Solution

Here's a different approach, without using the data filter:

dt = Open( "$sample_data/big class.jmp" );
ages = Data Table( "big class" ) << Summary( Group( :age ), Freq( "None" ), Weight( "None" ) );
sexes = Data Table( "big class" ) << Summary( Group( :sex ), Freq( "None" ), Weight( "None" ) );
deletedirectory("$temp/myPics");
createDirectory("$temp/myPics");
For( iage = 1, iage <= N Rows( ages ), iage++,
	thisAge = ages:age[iage];
	For( isex = 1, isex <= N Rows( sexes ), isex++,
		thisSex = sexes:sex[isex];
		eval(evalexpr(biv = dt << Bivariate(
			Y( :weight ),
			X( :height ),
			Automatic Recalc( 1 ),
			Fit Line( {Line Color( {213, 72, 87} )} ),
			where( age == expr(thisAge) & sex == expr(thisSex) )
		)));
		parentBox = Report( biv ) << parent;
		picture = parentBox << getpicture;
		picture << saveImage( "$temp/myPics/age" || Char( thisAge ) || "sex" || Char( thisSex ) || ".png", "png" );
		// optional: Open( "$temp/age" || Char( thisAge ) || "sex" || Char( thisSex ) || ".png" );
		biv<<closewindow;
	);
);
close(ages,"nosave");
close(sexes,"nosave");
show(filesInDirectory("$temp/myPics"));
Files In Directory("$temp/myPics") = {"age12sexF.png", "age12sexM.png", "age13sexF.png", "age13sexM.png", "age14sexF.png", "age14sexM.png", "age15sexF.png", "age15sexM.png", "age16sexF.png", "age16sexM.png", "age17sexF.png", "age17sexM.png"};

where clause above graphwhere clause above graph

In this case the where clause is above the platform's output, so I used the <<parent method to move up through the displaybox tree to include that outer box as well.

Craige
4 REPLIES
txnelson

Super User

Joined:

Jun 22, 2012

My first point, is that you should not be reading the Discussions to learn how to script JMP.  You should be reading the JSL Scripting Guide.

     Help==>Books==>Scripting Guide

Then if you can't get things to work, then the Discussion Community is a great resource to help you.

Let me take a wack at the questions you ask. 

1.  How do you use a local data filter and then save the output.

Below is a crude script that will show you how to do this in a very unfancy way

dt=Open(<path to your data table>);
gb=Graph Builder(
	Size( 527, 453 ),
	Show Control Panel( 0 ),
	Variables( X( :weight ), Y( :height ) ),
	Elements( Points( X, Y, Legend( 13 ) ), Smoother( X, Y, Legend( 14 ) ) )
);

Thefilter=gb<<Local Data Filter(
	Add Filter(
		columns( :age, :sex ),
		Where( :age == {12, 13, 14} ),
		Where( :sex == "F" ),
		Display( :age, Size( 170, 96 ), List Display )
	)
);

report(gb)<<save picture( "path/to/example.png", "png" );

gb<<remove local data filter;

Thefilter=gb<<Local Data Filter(
	Add Filter(
		columns(  :sex ),
		Where( :sex == "F" ),
		Display( :age, Size( 170, 96 ), List Display )
	)
);

report(gb)<<save picture( "path/to/example.png", "png" );

gb<<remove local data filter;


// Add the remaining filter cases

close(dt,nosave);
gb << close window;

The code for the graph builder and each of the local filters is available under the red triangles.  If you select them and go to "Save Script" you will get the code required for the different cases you have.  Just start up Graph Builder.  Then save the script for the graph builder.  Then open the local filter.  Set it to your first case(where clauses) and then save it's script.  Next, change the local filter to the next case and save it's script....etc.

2. The statement below the graph is saved to the png

3. You just need to specify in the Save Picture function the path.  This can be programatically handled so that it can follow any naming method you want to use.

4. The sample script show the method to do this

5. There is very good documentation in the Scripting Guide on how to make an Addin.  It is a far too lengthy answer to be handled in the Discussion

 

Jim
vishwasanj

Frequent Contributor

Joined:

Dec 27, 2016

Thank you txnelson for the reply. It was very useful. If I wanted to do a for loop in a data filter, is it possible to do it? That it can automatically go through each condition and plot the graphs. Like you suggested, I will look into the Addin feature in the scripting guide.
txnelson

Super User

Joined:

Jun 22, 2012

Yes, a For loop is available.  JSL is a very complete language, with all of the functionality one would expect from a computer language.

I suggest that you read the first few chapters of the Scripting Guide, so you can get a feeling for all of the components of the language and how to implement them.

If you could give me a little information about what computer languages you work with, it would help me in providing you with JSL examples in terms that you are familiar with.

Jim
Craige_Hales

Staff

Joined:

Mar 21, 2013

Solution

Here's a different approach, without using the data filter:

dt = Open( "$sample_data/big class.jmp" );
ages = Data Table( "big class" ) << Summary( Group( :age ), Freq( "None" ), Weight( "None" ) );
sexes = Data Table( "big class" ) << Summary( Group( :sex ), Freq( "None" ), Weight( "None" ) );
deletedirectory("$temp/myPics");
createDirectory("$temp/myPics");
For( iage = 1, iage <= N Rows( ages ), iage++,
	thisAge = ages:age[iage];
	For( isex = 1, isex <= N Rows( sexes ), isex++,
		thisSex = sexes:sex[isex];
		eval(evalexpr(biv = dt << Bivariate(
			Y( :weight ),
			X( :height ),
			Automatic Recalc( 1 ),
			Fit Line( {Line Color( {213, 72, 87} )} ),
			where( age == expr(thisAge) & sex == expr(thisSex) )
		)));
		parentBox = Report( biv ) << parent;
		picture = parentBox << getpicture;
		picture << saveImage( "$temp/myPics/age" || Char( thisAge ) || "sex" || Char( thisSex ) || ".png", "png" );
		// optional: Open( "$temp/age" || Char( thisAge ) || "sex" || Char( thisSex ) || ".png" );
		biv<<closewindow;
	);
);
close(ages,"nosave");
close(sexes,"nosave");
show(filesInDirectory("$temp/myPics"));
Files In Directory("$temp/myPics") = {"age12sexF.png", "age12sexM.png", "age13sexF.png", "age13sexM.png", "age14sexF.png", "age14sexM.png", "age15sexF.png", "age15sexM.png", "age16sexF.png", "age16sexM.png", "age17sexF.png", "age17sexM.png"};

where clause above graphwhere clause above graph

In this case the where clause is above the platform's output, so I used the <<parent method to move up through the displaybox tree to include that outer box as well.

Craige