cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Browse apps to extend the software in the new JMP Marketplace
Choose Language Hide Translation Bar
XanGregg
Staff
Reply All: Scientific notation such as 6.02×10²³ using custom axis formats

A recent wishlist item asked for a number format which was a version of scientific notation using superscript exponentiation instead of the computerese "e" separators for powers of 10. In other words, 3.4 × 10⁵ instead of 3.4e+5. Since superscripted digits are available as Unicode characters, it's possible to write such numbers as regular text, without the need for explicit superscripting. And that means we can get such numbers on an axis with a custom label format.

Graph axes have long supported custom label formats, which are JSL expressions that can produce arbitrary axis labels. Here's an example that adds "°F" to the y-axis labels.

XanGregg_2-1666365134406.png

I made it by picking Custom as the Format in the Axis Settings dialog.

XanGregg_0-1666364992985.png

And then clicking "Custom Format" to bring up a version of the Formula Editor to create this simple formula.

XanGregg_1-1666365102304.png

The formula for scientific is more complicated but still fits within the framework. I created this formula, which starts with JMP's regular scientific notation and then replaces the exponent's digits with the corresponding superscripted characters.

Local( {supers = "⁰¹²³⁴⁵⁶⁷⁸⁹", d, parts},
	parts = Words( Format( value, "Scientific", width, dec ), "e" ); // split on e
	Substitute Into( parts[2], "+", "", "-", "⁻" ); // ignore +, superscript -
	For( d = 0, d <= 9, d++, // superscript each digit
		Substitute Into( parts[2], Char( d ), Substr( supers, d + 1, 1 ))
	);
	if (value == 0, "0", parts[1] || " × 10" || parts[2]); // add x10 unless 0
)

Here's a graph using that format.

XanGregg_3-1666365764470.png

 

Finally, here's the entire script for the graph, with the custom format as a part of the axis customizations and data filter to just show the top states.

Open( "$SAMPLE_DATA/Corn Wheat Soybean Production.jmp" );
Graph Builder(
	Transform Column(
		"Maximum[Commodity Acres Planted][State,Commodity]",
		Formula( Col Maximum( :Commodity Acres Planted, :State, :Commodity ) )
	),
	Size( 658, 487 ),
	Show Control Panel( 0 ),
	Variables(
		X( :Year ),
		Y( :Commodity Acres Planted ),
		Group X( :Commodity ),
		Overlay( :State )
	),
	Elements( Points( X, Y, Legend( 35 ) ), Smoother( X, Y, Legend( 36 ) ) ),
	Local Data Filter(
		Add Filter(
			columns( :"Maximum[Commodity Acres Planted][State,Commodity]"n ),
			Where(
				:"Maximum[Commodity Acres Planted][State,Commodity]"n >= 4658000
			)
		)
	),
	SendToReport(
		Dispatch( {}, "Year", ScaleBox,
			{Min( 1999.5 ), Max( 2017.5 ), Inc( 10 ), Minor Ticks( 1 )}
		),
		Dispatch( {}, "Commodity Acres Planted", ScaleBox,
		{Format( "Custom",
			Formula(
				Local( {supers = "⁰¹²³⁴⁵⁶⁷⁸⁹", d, parts},
					parts = Words( Format( value, "Scientific", width, dec ), "e" );
					Substitute Into( parts[2], "+", "", "-", "⁻" );
					For( d = 0, d <= 9, d++,
						Substitute Into( parts[2], Char( d ), Substr( supers, d + 1, 1 ))
					);
					if (value == 0, "0", parts[1] || " × 10" || parts[2]);
				)
			)
		), Min( 0 ), Max( 15.5e6 ), Inc( 5e6 ), Minor Ticks( 4 )}
	))
);

 

Last Modified: Oct 21, 2022 11:30 AM
Comments