cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
  • JMP 19 is here! See the new features at jmp.com/new.
  • Register to attend Discovery Summit 2025 Online: Early Users Edition, Sept. 24-25.
Choose Language Hide Translation Bar
scott1588
Level IV

Problems with drawing lines and arrows on graphs

I'm trying some experiments to figure out how to draw lines and arrows on a graph in JSL. There is not much that has helped me in the Scripting Guide and I didn't see anything previously posted in the community. I have uploaded my JSL script and data table below.

 

In the data table, I have calculated the coordinates for a unit circle at 5 degree intervals. I plotted these with Graph Builder...

 

scott1588_0-1758696854623.png

 Initially, what I would like to do is script an arrow from the origin to each point. Here is the script I am using. I don't get any errors when I run it but it never draws the arrows. I have tried putting the FOR loop within the Graph Builder block as shown here and also outside the block. I can't seem to get either to work.

 

Names Default To Here (1);

dt = "Circle Arrow Data";


Graph Builder(
	Size( 540, 540 ),
	Graph Spacing( 10 ),
	Spacing Borders( 1 ),
	Variables( X( :x coord ), Y( :y coord ) ),
	Elements( Points( X, Y, Legend( 3 ) ) ),
	For( i=0, i<360, i+=5,
		Arrow( {0,:x coord[i]}, {0, :y coord[i]})
	)
);

Ultimately, my goal is to only have the arrows appear when a row or rows are selected but obviously I need to get this working first. This is really about showing wind direction on a graph but I'm taking baby steps in understanding how to draw on graphs.

 

Thanks in advance for any guidance provided.

 

 

 

 

3 REPLIES 3
hogi
Level XIII

Re: Problems with drawing lines and arrows on graphs

excellent timing : )

 

new in JMP19:
Can Vector Field Charts Help Explain Performance in the Last Super Bowl? 

hogi_0-1758702668096.png

 




New Column( "x_0",	Formula( 0 ));
New Column( "y_0",	Formula( 0 ));

Graph Builder(
	Variables( X( :x_0 ), X( :x coord, Position( 1 ) ), Y( :x_0 ), Y( :y coord, Position( 1 ) ) ),
	Elements(
		Line(
			X( 1 ),	X( 2 ),
			Y( 1 ),	Y( 2 ),
			Ordering( "Within Row" ),
			Connection( "Arrow" )
		)
	)
);

 

scott1588
Level IV

Re: Problems with drawing lines and arrows on graphs

Hey @hogi thanks for the script. It works great.

 

I'm trying to understand it though... so a couple of questions.

 

1) What does the Position parameter do?

2) Where do the 1 and 2 come from in the X and Y arguments?

3) What does the Ordering ("Within Row") do? 

 

There seems to be very incomplete documentation on these functions in the scripting help and scripting index.

 

Again, thanks.

hogi
Level XIII

Re: Problems with drawing lines and arrows on graphs

I agree, the scripting index isn't as good as the ones in other programs like Mathematica or Matlab, or the huge online documentation for Python and C++.There are some activities to improve the situation: Comprehensive scripting index 

On the other hand, there are many things you can learn by doing. Just open Graph Builder and create your graph using the drag-and-drop feature. It just takes some seconds - and optimizing the plot takes another few seconds. Then "Save Script to data table" and compare what you did with what you find in the code. 

 

  • row order is a new feature in JMP19. It can be used when sets of coordinates are used for X & Y.
    and it's the new default option for this case
    [notice: the graph doesn't change when I activate the option]
  • let's drag the coordinates into the plot, first x_0 and y_0
    Variables( X( :x_0 ), Y( :y_0 ) ),
  • then x_coord / y_coord 
    Variables( X( :x_0 ), X( :x coord, Position( 1 ) ), Y( :x_0 ), Y( :y coord, Position( 1 ) ) )​
  • now, we just have to activate the line plot. By default, it uses all available coordinated:
    X(1) is x_0
    X(2) is x_coord
    	Elements(
    		Line(
    			X( 1 ),	X( 2 ),
    			Y( 1 ),	Y( 2 ),
    		)
    	)
    we can also deactivate variables via:
    hogi_1-1758857327909.png

    Then the code will reduce to:

    	Elements(
    		Line( X( 1 ), Y( 1 ),

Plots with lines and arrows connecting multiple coordinates: A great improvement in JMP19. 


Plots with lines and arrows connecting multiple coordinates. A great improvement in JMP19!

Just imagine that instead of arrows, you want to plot three sets of coordinates (points) within the same plot. Then you have to add three point plots to the graph and disable the 'other' coordinates three times. It works, but it's messy!

hogi_2-1758858042334.png

Just imagine if you wanted to plot ten sets of coordinates!
A logical next step would be to copy the new 'within row' functionality to point plots.
Multiple x and y data sets plotted as "pairs" without having to stack columns 
I really hope this feature gets implemented soon!

Recommended Articles