cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Check out the JMP® Marketplace featured Capability Explorer add-in
Choose Language Hide Translation Bar
robust1972
Level IV

how to automate the exporting of grouped graphs to .jpg with scripting

hi, all

how to automate the exporting of grouped graphs to .jpg with scripting? any helps and hints will be appreciated.

I used the sample data animals to illustrate what I what to do. I plot the data like below. I intend to export each graph/plot with the title part and legend into a single .jpg or whatever format with scripting.

1stly, In my data, I do not know how many plots will be plotted before hand. 2nd thing is that I am not familiar the construct of the plots, and how to handle them one by one in jmp script.

Oneway(

  Y( :miles ),

  X( :season ),

  All Graphs( 0 ),

  Plot Quantile by Actual( 1 ),

  Line of Fit( 0 ),

  X Axis Proportional( 0 ),

  Grand Mean( 0 ),

  By( :species )

);

12744_pastedImage_0.png

1 ACCEPTED SOLUTION

Accepted Solutions
Craige_Hales
Super User

Re: how to automate the exporting of grouped graphs to .jpg with scripting

Open( "$sample_data/animals.jmp" );

p = Oneway(

  Y( :miles ),

  X( :season ),

  All Graphs( 0 ),

  Plot Quantile by Actual( 1 ),

  Line of Fit( 0 ),

  by( species )

);

// p is a { list } of platforms, 1 per by group value

For( ip = 1, ip <= N Items( p ), ip++,

  r = Report( p[ip] ); // get the report

  image = r << getpicture;

  image << savepicture( "$temp/picture" || Char( ip ) || ".png", "png" );

  Open( "$temp/picture" || Char( ip ) || ".png" );

);


12748_picture1.png

and

12749_picture2.png

Craige

View solution in original post

7 REPLIES 7
Craige_Hales
Super User

Re: how to automate the exporting of grouped graphs to .jpg with scripting

Open( "$sample_data/animals.jmp" );

p = Oneway(

  Y( :miles ),

  X( :season ),

  All Graphs( 0 ),

  Plot Quantile by Actual( 1 ),

  Line of Fit( 0 ),

  by( species )

);

// p is a { list } of platforms, 1 per by group value

For( ip = 1, ip <= N Items( p ), ip++,

  r = Report( p[ip] ); // get the report

  image = r << getpicture;

  image << savepicture( "$temp/picture" || Char( ip ) || ".png", "png" );

  Open( "$temp/picture" || Char( ip ) || ".png" );

);


12748_picture1.png

and

12749_picture2.png

Craige
robust1972
Level IV

Re: how to automate the exporting of grouped graphs to .jpg with scripting

Thanks,Craig!

Would it be possible to name the pictures by the title of the plots? As in my data, there are more than 20 combinations and it is hard to find the picture interested without this kind of naming convention.

Craige_Hales
Super User

Re: how to automate the exporting of grouped graphs to .jpg with scripting

Sure.  Note the regex that sanitizes the file name...you might want to adjust it for your needs.  As shown, it converts all odd looking character (spaces and equal sign in this case) to underscore.  Windows is probably OK with both of those, but they don't help some programs.

Open( "$sample_data/animals.jmp" );

p = Oneway(

  Y( :miles ),

  X( :season ),

  All Graphs( 0 ),

  Plot Quantile by Actual( 1 ),

  Line of Fit( 0 ),

  by( species )

);

// p is a { list } of platforms, 1 per by group value

For( ip = 1, ip <= N Items( p ), ip++,

    r = Report( p[ip] ); // get the report

    image = r << getpicture; // r *is* the outline

    title = (r << gettitle); // use the outline name

    // you *might* want to replace problematic characters:

    title = Regex( title, "[^a-zA-Z0-9]", "_", GLOBALREPLACE );

    path = "$temp/" || title || ".png";

    image << savepicture( path, "png" );

    Open( path );

);

Craige
robust1972
Level IV

Re: how to automate the exporting of grouped graphs to .jpg with scripting

Craig

Thank you again for timely response and solving the problem for me.

Is there a document or a way to check the architecture of the grouped plots, i.e. how to understand the tree structure and hierarchy of it.

Craige_Hales
Super User

Re: how to automate the exporting of grouped graphs to .jpg with scripting

Use the ShowTreeStructure command from the outer-most outline's open/close triangle:

12753_pastedImage_0.png

You'll get a view of the displaybox tree that makes up the report:

12754_pastedImage_1.png

For the by-group case, there is actually a listbox that holds all the reports together.  You don't see it in the ShowTreeStructure output because it is outside of the report that you clicked on.  In the example JSL, the JSL list holds all the platforms.  A platform is created for each by group, and a platform roughly corresponds to the red triangle.  The red triangle and the platform object both give you access to commands the platform understands (like "add a fitted line to the graph", etc)  In the example JSL, the loop runs over the platforms in the list and asks each platform for its displaybox tree (the report function).  That displaybox tree is what you see in the ShowTreeStructure output.

Craige
robust1972
Level IV

Re: how to automate the exporting of grouped graphs to .jpg with scripting

hi, Craig

how about the plots in graph builder? using same sample data plots as below. Please help me how do I call out the boxes in graph builder. I think its construct is different than that of by-group plots.

12772_pastedImage_0.png

Graph Builder(

  Fit to Window( "Off" ),

  Graph Spacing( 3 ),

  Spacing Borders( 1 ),

  Variables( X( :season ), Y( :miles ), Group X( :subject ), Group Y( :species ) ),

  Elements( Points( X, Y, Legend( 13 ) ) )

);

Craige_Hales
Super User

Re: how to automate the exporting of grouped graphs to .jpg with scripting

You could use the picture box to take a complete picture of a graph builder.

12780_pastedImage_0.png

Use a data filter if you need separate pictures of graphs of different subsets.

12781_pastedImage_1.png

gb = Graph Builder(

    Size( 522, 444 ),

    Show Control Panel( 0 ),

    Variables( X( :season ), Y( :miles ) ),

    Elements( Points( X, Y, Legend( 10 ) ) )

);

gb<< Local Data Filter(

            columns( :species, :subject ),

            Where( :species == "COYOTE" ),

            Where( :subject == 2 )

        );

gb<<remove local data filter;

gb<<  Local Data Filter(

            columns( :species, :subject ),

            Where( :species == "FOX" ),

            Where( :subject == 1 )

        );

report(gb)[pictureBox(1)] << savePicture("$temp/delememe.png", "png");

open("$temp/delememe.png");

Craige