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
Lharbicht
Level III

Scripting Y Axis to be Log scale

Hello,

 

I have script to make multiple histograms using stacked data. The y-axis used in the histogram is the stacked data column :Data, the x-axis used in the histogram is the stacked data column labels :Chemical Compound. Then I use Page (:Sample ID) to separate my graphs into one graph per sample. Depending on my dataset that I'm using the script for, I may have 2 samples, or 100 samples. My graphs work fine, however, I would like the y-axis to be in log scale. I've tried multiple ways of inserting code to do this, however, the most I've gotten to work is 1 graph in log scale, while the others are all linear. I've attached the code. The part that is sort of working is the 'ScaleBox (2),'. It changes the first graph to log, however, it leaves the remaining scales as linear. If I change the (2) to a (3) after 'ScaleBox' then the second graph in the group changes to log while the others remain linear. If I remove the (#) after 'ScaleBox' altogether, then none go to log. I've also tried inserting 'Left Y Log Scale (1)' into the Variables area but nothing.

 

I've attached a dataset to run with the script. Any help with this would be appreciated!

 

Thank you,

 

 

Graph Builder(
        Show Control Panel( 0 ),
	Variables( X( :Chemical Compound ), Y( :Data ), Page( :SampleID ) ),
	Elements( Bar( X, Y, Legend( 10 ) ) ),
	SendToReport(
			Dispatch(
			{},
			"Data",
			ScaleBox (2),
			{Scale( "Log" ), Format( "Best", 10 ), Min( 0.01 ), Max( 80 ), Inc( 1 ),
			Minor Ticks( 1 )}
		),
		Dispatch( {}, "400", LegendBox, {Set Title( "" )} ),
	)
);
1 ACCEPTED SOLUTION

Accepted Solutions
gzmorgan0
Super User (Alumni)

Re: Scripting Y Axis to be Log scale

I like to use XPath(). A single message applies to all objects found. See the last 2 lines of the script below.  Ther is a section and sample scripts for Xpath() and Find() in Chapter 6 of the 2nd edition of JSL Companion. You can find a simple example in the Scripting Index >Display Box > search for xpath.  To learn more about XPath syntax and functions, click here 

<https://www.tutorialspoint.com/xpath/xpath_quick_guide.htm>

 

gb = Graph Builder(
        Show Control Panel( 0 ),
	Variables( X( :Chemical Compound ), Y( :Data ), Page( :SampleID ) ),
	Elements( Bar( X, Y, Legend( 10 ) ) ),
	SendToReport(
//			Dispatch(
//			{},
//			"Data",
//			ScaleBox (2),
//			{Scale( "Log" ), Format( "Best", 10 ), Min( 0.01 ), Max( 80 ), Inc( 1 ),
//			Minor Ticks( 1 )}
//		),
		Dispatch( {}, "400", LegendBox, {Set Title( "" )} ),
	)
);

xx =gb << Xpath( "//ScaleBox[@charID='Data']");

xx << {Scale( "Log" ), Format( "Best", 10 ), Min( 0.01 ), Max( 80 ), Inc( 1 ), Minor Ticks(1) };

 

View solution in original post

5 REPLIES 5
pmroz
Super User

Re: Scripting Y Axis to be Log scale

Unfortunately you have to send the log Y axis message to each graph page.  This code works but shows errors in the log.  Hope someone has a cleaner solution for you.

EDIT 4-9-2018 I was looping over id_list and not unique_values.  Fixed code is below.

Get_unique_values = Function( {in_list},
      {Default Local}, 
      tmp = [=> 0]; 
      Insert Into( tmp, in_list ); 
      tmp << get keys; 
); 

dt = data table("Test Data");

id_list = column(dt, "Sample ID") << get values;
unique_values = get_unique_values(id_list);

gb = dt << Graph Builder(
	Size( 530, 1460 ),
	Show Control Panel( 0 ),
	Variables( X( :Chemical Compound ), Y( :Data ), Page( :Sample ID ) ),
	Elements( Bar( X, Y, Legend( 10 ) ) ),
);

for (i = 1, i <= nitems(unique_values), i++,
	gb << SendToReport(
		Dispatch( {}, "Data", ScaleBox( i + 1 ),
			{Scale( "Log" ), Format( "Best", 10 )}
		)
	);
);

 

gzmorgan0
Super User (Alumni)

Re: Scripting Y Axis to be Log scale

I like to use XPath(). A single message applies to all objects found. See the last 2 lines of the script below.  Ther is a section and sample scripts for Xpath() and Find() in Chapter 6 of the 2nd edition of JSL Companion. You can find a simple example in the Scripting Index >Display Box > search for xpath.  To learn more about XPath syntax and functions, click here 

<https://www.tutorialspoint.com/xpath/xpath_quick_guide.htm>

 

gb = Graph Builder(
        Show Control Panel( 0 ),
	Variables( X( :Chemical Compound ), Y( :Data ), Page( :SampleID ) ),
	Elements( Bar( X, Y, Legend( 10 ) ) ),
	SendToReport(
//			Dispatch(
//			{},
//			"Data",
//			ScaleBox (2),
//			{Scale( "Log" ), Format( "Best", 10 ), Min( 0.01 ), Max( 80 ), Inc( 1 ),
//			Minor Ticks( 1 )}
//		),
		Dispatch( {}, "400", LegendBox, {Set Title( "" )} ),
	)
);

xx =gb << Xpath( "//ScaleBox[@charID='Data']");

xx << {Scale( "Log" ), Format( "Best", 10 ), Min( 0.01 ), Max( 80 ), Inc( 1 ), Minor Ticks(1) };

 

pmroz
Super User

Re: Scripting Y Axis to be Log scale

I didn't realize xpath could be used for this.  Nice clean solution!

Lharbicht
Level III

Re: Scripting Y Axis to be Log scale

Thank you for this solution! I will checkinto this some more.

 

Lharbicht
Level III

Re: Scripting Y Axis to be Log scale

Hello!

 

I've been using this solution for my log scale graphing needs. It works great. However, if I want to graph a large number of samples (say > 50) it gives an error (see below). Has anyone run into this before? I've tried adding 'wait();' before and after and in different areas thinking my code just needed more time. It works fine for < 50 samples, anything above gives the error.

Excessive depth in document: 256 use XML_PARSE_HUGE option

 in access or evaluation of 'Xpath' , Xpath( "//ScaleBox[@charID='Rel TEQ']" ) /*###*/

 

Here's my code.

dtstacked3:Parameter3 << set property( "Row Order Levels", 1 );
dtstacked3:Sample ID << set property ("Row Order Levels",1);
gb3 = dtstacked3 << Graph Builder(
	Show Control Panel( 0 ),
	Variables( X( :Parameter3 ), Y( :Rel TEQ ), Page( :Sample ID ), Color( :Rel TEQ 2 ) ),
	Elements( Bar( X, Y, Legend( 6 ) ) ),
	SendToReport(
		Dispatch( {}, "400", ScaleBox, {Legend Model( 6, Properties( 0, {gradient(
						{Color Theme(
							{"Paired Copy 2 2502", 8193, {{254, 207, 132}, {254, 207,
							132}, {254, 207, 132}, {254, 207, 132}, {254, 207, 132},
							{254, 207, 132}, {114, 171, 187}, {114, 171, 187}, {114,
							171, 187}, {114, 171, 187}, {114, 171, 187}}}
						), Scale Values( [0 1] ), Width( 12 ), Discrete Colors( 1 )}
					)}) )} ),
		Dispatch( {}, "400", LegendBox, {Set Title( "" )} )
	)
);

xx3 = gb3 << Xpath("//ScaleBox[@charID='Rel TEQ']");
xx3 << {Scale("Log"), Format("Best", 10), Min(0.1), Max(80), Inc(1), Minor Ticks(1)};

gb3 << on close( Close( dtstacked3, nosave ) );

Thanks!

 

Lacey