making simple plots and graphs

Learning APL or new to Dyalog? Ask "silly" questions here, without fear...

Re: making simple plots and graphs

Postby MBaas on Thu Jun 02, 2016 10:12 am

Sorry for misleading you, this is more painful that it should be ;-)
Let's focus on getting on sample for a nice linechart:

Code: Select all
)load sharprain
)cs Samples
)ed Iceland


Have a look at the code...and then replace last line with this:
Code: Select all
PG←#.ch.Close ⋄ r←'#.Samples.PG  View ''''⍝ for the Glacier data'

and then you should be able to execute
Code: Select all
Iceland
User avatar
MBaas
 
Posts: 156
Joined: Thu Oct 16, 2008 1:17 am
Location: Gründau / Germany

Re: making simple plots and graphs

Postby Stu on Thu Jun 02, 2016 2:51 pm

We're getting closer! I can now see lots of coded examples. This is good. However, I have encountered some problems. When I modify "Iceland" as you say, I get this:

*** ERROR *** Style : Unsupported : XS ZANG
*** ERROR *** Style : Unsupported : XS ZANG
#.Samples.PG View'' ⍝ for the Glacier data

I also tried "Multiple", "Timeseries", and "Sample". With these I get:

VALUE ERROR
View[2] r←#.PostScrp.View arg
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: making simple plots and graphs

Postby MBaas on Thu Jun 02, 2016 5:29 pm

Not at the PC atm, so I can't check, but I guess that the 3 failing fns will need that same last-line-fix as before.
The error-msgs indicate that certain features (mentioned in the msg) are not available, but the graph might still be useable...
User avatar
MBaas
 
Posts: 156
Joined: Thu Oct 16, 2008 1:17 am
Location: Gründau / Germany

Re: making simple plots and graphs

Postby Stu on Fri Jun 03, 2016 12:41 am

It appears that the final line of each of the Samples must be:
R←'#.View #.Samples.PG'
Then you assign the value of, e.g., Timeseries, to some variable, say R:
R←Timeseries
R will then contain
#.View #.Samples.PG
which you then execute from the command line (or with ⍎?) to display the graph.

Is this more or less how the examples in sharprain are supposed to work?
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: making simple plots and graphs

Postby MBaas on Fri Jun 03, 2016 4:45 am

Hmmm, was'n it #.Samples.PG View'' that we changed to in thebIcekand-example?
In general,, the examples never output directly but just return the viewable code. In your own fn, there's no need to follow that style, instead of outputting that..View..-stuff, you can do it right away (no quotes, no excute).
User avatar
MBaas
 
Posts: 156
Joined: Thu Oct 16, 2008 1:17 am
Location: Gründau / Germany

Re: making simple plots and graphs

Postby Stu on Sat Jun 04, 2016 12:49 am

The last line in all of the examples has to be: #.View #.Samples.PG. If, instead, you just write View #.Samples, you get this error message:

VALUE ERROR
View[2] r←#.PostScrp.View arg

Some of the other examples in Samples generate other error messages that I currently don't understand.
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: making simple plots and graphs

Postby Stu on Sat Jun 04, 2016 4:15 pm

Thanks for taking the time to help me out with this problem. I think I've now got the hang of using the Sharp Plot Samples. I hadn't worked with namespaces before and that was hindering me from understanding of what was going on. The chapter on namespaces in "Mastering Dyalog" was very helpful.
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: making simple plots and graphs

Postby Stu on Mon Jun 06, 2016 1:34 am

I need one last bit of help to get my simple plotting function going. Most of it works fine: the two vectors, "Vertical" and "Horizontal," are nicely plotted with solid and dashed lines, respectively, the heading is centered at the top, and the X and Y tick marks are correct. The only problem is that the keys are small empty boxes instead of short solid or dashed line segments. I've looked at all the examples in Samples, but I can't figure out how a key gets associated with the corresponding line on the plot. Here are the last few lines of my function:

ch.Plot mat ⍝ 3×n matrix: one row of X-ordinates plus two rows of data
ch.SetKeyText'Vertical,Horizontal'
PG←ch.Close
View PG

To get as far as I have, I've had to so something I really dislike: writing "experimental" programs to see what the interpreter/compiler does. The Sharp Plot documentation, which appears to be written for an experienced C++ programmer isn't much help.
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

Re: making simple plots and graphs

Postby MBaas on Mon Jun 06, 2016 10:12 am

I'm not sure I understand exactly what you're after - does the Keystyle-property help? If not, would it be possible to post a complete example, so it's easier to repro and fix?
User avatar
MBaas
 
Posts: 156
Joined: Thu Oct 16, 2008 1:17 am
Location: Gründau / Germany

Re: making simple plots and graphs

Postby Stu on Mon Jun 06, 2016 1:48 pm

Yes, of course, I should have sent the whole thing. Here it is:

plott;⎕IO
v←(32?32)÷32 ⍝ Fake data for testing
h←(32?32)÷32 ⍝ Fake data for testing
⎕IO←1
diff←(⍴v)-⍴h
:If diff=0 ⍝ v and h are of the same length
n←⍴v
:ElseIf diff>0 ⍝ v is longer
n←⍴v
h←n↑h
:Else ⍝ h is longer
n←⍴h
v←n↑v
:EndIf
mat←(3,n)⍴0
mat[1;]←⍳n
mat[2;]←v
mat[3;]←h
ch.DefineFont'GA' 'Garamond'
ch.New 0 0 432 300
ch.Set'DStyle' 'Rows'
ch.Set('style' 'XYPLOT,BOXED,NOMARK,SURFACE,GRID')('Mleft' 25)('Mright' 24)('HMAR' 50 24)
ch.Set'Ystyle' 'LEFT'
ch.Set('Hfont' 'GABI,12')('Lfont' 'GA')
ch.Set('XRANGE' 0(⌈/mat[1;]))('YRANGE' 0((⌈/mat[2;])⌈(⌈/mat[3;])))
ch.Set('PATTERN' 0)
ch.Set'HEAD' 'Correlation'
ch.SetKeyText'Vertical,Horizontal'
ch.Plot mat
PG←ch.Close
View PG
Stu
 
Posts: 97
Joined: Thu Dec 31, 2015 1:30 am

PreviousNext

Return to New to Dyalog?

Who is online

Users browsing this forum: No registered users and 1 guest