turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- JMP User Community
- :
- Discussions
- :
- Creating customized graphs inside a function

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 10, 2012 6:32 AM
(1522 views)

I want to write a function which will plot a chart using a specific set of parameters, and then call it multiple times as in the simple example below. This example doesn't actually work however, presumably because the "X" that I'm referencing inside the graph box is local to the "myplot" function. What is the easiest way I could modify the following so that it would work as I intend, i.e. the letters "A", "B", "C" and "D" should be written inside each of the four charts respectively?

myplot1 = Function**(** **{**X**}**,

gb = Graph Box**(**

FrameSize**(** **100**, **100** **)**,

X Scale**(** **0**, **10** **)**,

Y Scale**(** **0**, **100** **)**,

Text**(** center justified, **{****5**, **50}**, X **)**

**)**

**)**;

nw1 = New Window**(** "Four Charts",

Lineup Box**(** N Col**(** **2** **)**, myplot1**(** "A" **)**, myplot1**(** "B" **)**, myplot1**(** "C" **)**, myplot1**(** "D" **)** **)**

**)**;

Many thanks

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 10, 2012 6:49 AM
(2908 views)

Solution

You need to substitute the current value into your Graph Box expression on each call to the function, like this:

myplot1 = Function**(** **{**X**}**,

gb = Substitute(Expr(

Graph Box**(**

FrameSize**(** **100**, **100** **)**,

X Scale**(** **0**, **10** **)**,

Y Scale**(** **0**, **100** **)**,

Text**(** center justified, **{****5**, **50}**, xxx **)**

** )),**

** Expr(xxx),**

** X**

** );**

** gb // to evaluate the Graph Box expression, alternatively put substitute command inside Eval()**

**)**;

nw1 = New Window**(** "Four Charts",

Lineup Box**(** N Col**(** **2** **)**, myplot1**(** "A" **)**, myplot1**(** "B" **)**, myplot1**(** "C" **)**, myplot1**(** "D" **)** **)**

**)**;

6 REPLIES

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 10, 2012 6:49 AM
(2909 views)

You need to substitute the current value into your Graph Box expression on each call to the function, like this:

myplot1 = Function**(** **{**X**}**,

gb = Substitute(Expr(

Graph Box**(**

FrameSize**(** **100**, **100** **)**,

X Scale**(** **0**, **10** **)**,

Y Scale**(** **0**, **100** **)**,

Text**(** center justified, **{****5**, **50}**, xxx **)**

** )),**

** Expr(xxx),**

** X**

** );**

** gb // to evaluate the Graph Box expression, alternatively put substitute command inside Eval()**

**)**;

nw1 = New Window**(** "Four Charts",

Lineup Box**(** N Col**(** **2** **)**, myplot1**(** "A" **)**, myplot1**(** "B" **)**, myplot1**(** "C" **)**, myplot1**(** "D" **)** **)**

**)**;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 10, 2012 8:13 AM
(1454 views)

Thanks - that's perfect. May I ask a related question while I'm thinking about it? If I wanted to generalize that to incorporating two or more parameters, could I do that essentially the same way, and if so, how would that change the syntax?

Again, many thanks

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 10, 2012 8:26 AM
(1454 views)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 10, 2012 9:40 AM
(1454 views)

Sure - the sort of thing I was thinking of is a situation where I'd feed into the function several parameters telling the chart how I want different features of it displayed. For example in the case of just two parameters, if I wanted a single window showing several different polynomial fits to the same data, with each one having a different title - or to generalise it further, I might want to feed in the lower and upper limits of the axes, the colors of the fitted lines, the frame size etc.

Since I started composing this reply however, I’ve found a neat way to do exactly what I want, just by supplying a list as the argument to the function instead of a single parameter:

myplot1 = Function**(** **{**X**}**,

gb = Substitute**(**

Expr**(**

Graph Box**(**FrameSize**(** **100**, **100** **)**,

X Scale**(** **0**, **10** **)**,

Y Scale**(** **0**, xxx**[****1]** **)**,

Text**(** center justified, **{****5**, **4***xxx**[****1]**/**5}**, xxx**[****2]** **)**;

**)**

**)**,

Expr**(** xxx **)**, X

**)**;

gb

**)**;

nw1 = New Window**(** "Four Charts",

Lineup Box**(** N Col**(** **2** **)**,

myplot1**(** **{****50**, "Linear"**}** **)**, myplot1**(** **{****70**, "Quadratic"**}** **)**,

myplot1**(** **{****90**, "Cubic"**}** **)**, myplot1**(** **{****200**, "Quartic"**}** **)** **)**

**)**;

So many thanks – that answers everything!

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 10, 2012 1:01 PM
(1454 views)

If you wanted to make your function calls more "traditional," you could do the following with the same effect:

myplot1 = Function**(** **{**X1, X2**}**,

gb = Substitute**(**

Expr**(**

Graph Box**(**FrameSize**(** **100**, **100** **)**,

X Scale**(** **0**, **10** **)**,

Y Scale**(** **0**, xxx **)**,

Text**(** center justified, **{****5**, **4***xxx/**5}**, yyy **)**;

** )**

** )**,

Expr**(** xxx **)**, X1,

Expr( yyy ), X2

** )**;

gb

**)**;

nw1 = New Window**(** "Four Charts",

Lineup Box**(** N Col**(** **2** **)**,

myplot1**(** **50**, "Linear" **)**, myplot1**(** **70**, "Quadratic" **)**,

myplot1**(** **90**, "Cubic" **)**, myplot1**(** **200**, "Quartic" **)**

** )**

**)**;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Get Direct Link
- Email to a Friend
- Report Inappropriate Content

Jan 10, 2012 1:45 PM
(1454 views)