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.

 

 

 

 

1 ACCEPTED SOLUTION

Accepted Solutions
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" )
		)
	)
);

 

View solution in original post

8 REPLIES 8
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!

scott1588
Level IV

Re: Problems with drawing lines and arrows on graphs

So the 1 and 2 arguments in the X and Y functions are just the order in which they are listed in the variables function? Am I understanding this correctly?

 

Then what does the Position(1) do in the Variables function? It would seem like this would make the :x coord and y: coord 1 not the x_0 y_0.

 

Sorry. This is just a bit confusing for me.

scott1588
Level IV

Re: Problems with drawing lines and arrows on graphs

Ahhh... So I took the position(1) out and ran the script. This is what I got...

 

scott1588_0-1758917718343.png

So the way the variables are added would result in four separate graphs. The Position command selects which of the graphs to display.

 

I think that's right...

 

I'll play around with this some more. This would make a great tutorial video at some point,

 

Thanks for all your help on this

hogi
Level XIII

Re: Problems with drawing lines and arrows on graphs

: )
As promised, it's really easy to learn from the scripts "by doing"!

Besides that, there's a good chance that this way the learning will stick much better.

Yes, you can add the Position(1) also to the first entry. But that's the default.
So, without the Position(1) for the second argument [to force the value to be added to the first "subplot"] it would be Position(2)

scott1588
Level IV

Re: Problems with drawing lines and arrows on graphs

Yes. I agree. But sometimes its still difficult to understand what is going on.

 

For example, I replaced Position(1) with Position(2) thinking it would show a different quadrant of the graph. But... it did nothing. So the 1 in Position(1) is likely a boolean.

 

I can find nothing on any of this either on line or in the scripting index or the online help. Maybe I'm just looking in the wrong place.

 

At any rate, thanks again.

hogi
Level XIII

Re: Problems with drawing lines and arrows on graphs

the wrong way  ...

 

Believe me, I did not generate the code below after learning JSL.
vice versa: 
I created the code "with GraphBuilder" - now we can learn ...

Names Default to Here(1);
dt = Open( "$SAMPLE_DATA/Big Class Families.jmp" );
Graph Builder(
	Size( 437, 413 ),
	Summary Statistic( "Median" ),
	Graph Spacing( 4 ),
	Variables(
		X( :height ),
		Y( :name ),
		Y( :weight ),
		Y( :height, Position( 2 ) ),
		Y( :age ),
		Overlay( :sex )
	),
	Elements( Position( 1, 1 ), Points( X, Y, Legend( 89 ) ) ),
	Elements(
		Position( 1, 2 ),
		Points( X, Y( 1 ), Y( 2 ), Legend( 1 ) ),
		Smoother( X, Y( 1 ), Y( 2 ), Legend( 2 ) )
	),
	Elements( Position( 1, 3 ), Points( X, Y, Legend( 90 ) ) )
);


if there are just 2 items, there is no difference between adding a second entry - and adding a second entry as second.
Position(2) makes sense for three and more items. By default, the third item is added as third. If you want to do something else, you can add it to position(2).



Recommended Articles