HP Forums
Plot Values from a List Gen. by Program - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: Plot Values from a List Gen. by Program (/thread-2855.html)



Plot Values from a List Gen. by Program - hof - 01-14-2015 07:28 AM

Hello,

I'm new to this forum and new to the HP Prime.
I bought it in spite of all the criticism and must say that it works perfect for me. (latest firmware)
It's my first programmable calculator and I think it offers a large range of features.
Of course in comparision to matlab and mathcad there is still a way to go ;-), but for a portable device with such a long working duration on a battery its very nice.
I personaly use it in engineering and for making quick estimations in discussions.
So if i'm being asked I can type in the question and can reply it's 42 ;-)

Ok, now for my simple question:
If I make a program, which depends for example on a lookup-table like a list L0.
Is it possible to plot the result, perhaps written to vector/list L1 to the plot screen including the x an y scale?
Or is there a better approach?


RE: Plot Values from a List Gen. by Program - Snorre - 01-14-2015 10:44 AM

Hello hof,

(01-14-2015 07:28 AM)hof Wrote:  [...]
Ok, now for my simple question:
If I make a program, which depends for example on a lookup-table like a list L0.
Is it possible to plot the result, perhaps written to vector/list L1 to the plot screen including the x an y scale?
[...]
yes it is.
My basic approach for plotting L0 vs L1 would utilize the "Statistics 2Var"-App and look like:
Code:
BEGIN
  // ...
  STARTAPP("Statistics 2Var");  // Set current app.
  C1:=L0; C2:=L1;    // Copy lists to app data columns.
  SetIndep(S1,C1);   // Dataset 1 is column 1 ...
  SetDepend(S1,C2);  // ... vs column 2.
  Fit:=1;  // Turn fit plot off, since we're interested in the data points only.
  STARTVIEW(9);      // Show autoscaled plot.
END;

Greetings


RE: Plot Values from a List Gen. by Program - hof - 01-14-2015 09:56 PM

Hello Snorre,

thanks, it works fine and partly solves the problem.

I actually thought of a graphics output like in excel where x and y axis are visible with numbers.
But as a first step its okay ;-)


RE: Plot Values from a List Gen. by Program - DrD - 01-14-2015 10:32 PM

Here is a code fragment you might like to review. It might serve as a building block for your own specific needs. (It's just a quick framework, not a complete charting program). The layout allows space to accommodate soft keys (Drawmenu) below, if you wanted to include it. X and Y pixels are equal for this example.

Code:

EXPORT XYChart()
BEGIN
LOCAL t,x;

RECT();                                // Clear figure

LINE_P(51,4,51,214,RGB(128,128,128));                 // v spine:  from 4 to 214 pixels, 210 pixels long
LINE_P(51,109,261,109,RGB(128,128,128));            // h spine:  from 51 to, 261 pixels,  210 pixels wide
TEXTOUT_P("Your Data",263,105,1,RGB(128,128,128));  
          
for t from 4 to 214 step 210/10 do                           // V subticks,  4 pixels wide             
  LINE_P(49,t,53,t,RGB(128,128,128));              
  TEXTOUT_P((-t+109)/105,30,t-4,1,RGB(128,128,128));  // Annotate V-Axis
end;

x:=1;
for t from 51 to 261 step 210/10 do                    // H subticks. 4 pixels wide
  LINE_P(t,107,t,111,RGB(128,128,128));
  x:=NOT(x);
  if x then TEXTOUT_P((t-156)/105,t-4,113,1,RGB(128,128,128)); end;    // Annotate H-Axis  
end;                                                                                                  // H subticks

FREEZE;

RETURN; 
END;

Good luck!

-Dale-


RE: Plot Values from a List Gen. by Program - Snorre - 01-14-2015 11:21 PM

Hello hof,

you can also set the plot window to show axis labels and numbers (only the current view limits per axis) by .
For more sophisticated graphing you should implement it by yourself as suggested by DrD, but that will be a tremendous task if you want to all the features of the builtin plot function (zooming, panning, tracing etc.).

It may be easier to define a VIEW function within an existing app which TEXTOUTs the numbers onto your current plot.
A skeleton might look like (but leaves much room for improvements):
Code:
VIEW "Show tick labels" ShowTickLabels()
BEGIN
  LOCAL d:=PX→C(C→PX(0,0)+4),
        x:=Xmin - Xmin MOD Xtick,
        y:=Ymin - Ymin MOD Ytick;
  WHILE x<Xmax DO
    TEXTOUT(x,x,d(2),1);
    x:=x+Xtick;
  END;
  WHILE y<Ymax DO
    TEXTOUT(y,d(1),y,1);
    y:=y+Ytick;
  END; 
END;

Greetings


RE: Plot Values from a List Gen. by Program - hof - 01-16-2015 09:10 AM

Thanks to you both for your nice work, I will try your suggestions in the next time.
My original thought was that this is an integrated feature of the calculator which would be very helpful.
I believe this should have been integrated in the first place and have been of a higher priority to the designers.
But at least it seems to be feasable in some way ;-), although its a bit disappointing.
Thanks again.