Conversation started Jun 16, 2020 at 14:31.
Jun 16, 2020 2:31 PM
Welcome to APL Cultivation!
Yay! What's today's topic?
Today is a very special occasion, as we have our fist ever guest speaker chatter, Nic, who will teach you about basic plotting in APL. Go ahead, @Nic !
Nic
Nic
Hello !
So let's use TIO
There is a bit of setup to do so that the chart is output as SVG encoded in a base64 data URI
Hi Nic.
Nic
Nic
Here's the setup :
https://tio.run/##fVTbbhNJEH33V9TbjLGTeBxisrEQIiawXpLAOhvuEerJtMcNPRe62zcuL@wqS8J6BUIrP61ACL4AEB/gP5kfCdU9PRALRMsaz3RXnao@dapIyheCMeFJeHwMuJx2zFSL9CUdkrEDzjVGhw5k//7XuunIHhFpyhPllEraNnv2N6iRyg5eDFmgerBOJG2cBhYr2fSZfpiN5j76SaqasXkxrgDaAD2r2eTQdY3/bLpaziYf6@Xs6J3GgJMrm/wPA7qvEiEh6RpvsEg5LGJl/zxzs8O3@qw8@9yAHy2NE/cjnwoDk2c8l5fZQrR6dvReJ5fDVxs6N7cxm@bf5ezgpUnCIKYkyFMaMuThIRWJBJVASBUQiPpcsZRTHbBhzGwoywvGcs6vty5sXLz0a/u3y5tb21eu/t7Z@WP32vUbN28Rfz@g3bDH7t3nUZykD4RU/cFwNH5Y8@rLp1caZ1Z/qSw5FjIvhwW@7VXy2@x9O63isbv8eMEyjnRpqvXdnLPOd0zpe0VMShaH4I8VtRdE00IAuRK2yH2622kj9iMnIIqssYiEdEkO
Jun 16, 2020 2:35 PM
I have a copy of 17.1 installed on this computer; would you please be sure to provide the information needed to do it in a local terp instead of (just) TIO?
Nic
Nic
Of course if you're running from APL directly, you can simply
`)load sharpplot`
Got it!
Nic
Nic
You'll see the minimal chart script which is
` InitCauseway ⍬
sp←⎕NEW Causeway.SharpPlot
sp.DrawLineGraph ⊂↓+\¯0.5+?5 1e2⍴0
View sp `
@Nic You can't do markdown in multi-line messages. Just use two messages.
Nic
Nic
ok
Jun 16, 2020 2:37 PM
@Nic Use Ctrl+K for a code block message.
Nic
Nic
So, in the TIO setup, to view the chart, you need to copy/paste the output URI into your web browser address bar
Sometimes the output URI is split on multiple lines in the output, so it's important to select it with CTRL+A which selects the whole text and not simply double-clicking on it which selects a single line (at least in firefox)
That should end up looking like this (your random numbers may vary):
Nic
Nic
Is there anyone who hasn't been able to display a chart ?
@Adám In fact in my TIO setup I use a fixed-seed ⎕RL so that everybody work on the same series
My chart has 4 separate lines drawn
@Nic RIDE works perfectly, which is my preferred WS anyway, but TIO doesn't...
@xpqz Same!
Jun 16, 2020 2:40 PM
(On RIDE, too)
Nic
Nic
@xpqz OK that's because you used the sample script from the sharpplot workspace, rather than the TIO sample. So it does work
Aye
Nic
Nic
So now that you're all set up, here's the question : what shall we do today ?
oh and the documentation can be found there :
https://sharpplot.com/
Typical samples for each chart type can be found on :
https://sharpplot.com/Charts.htm
Code samples are in C#, but there is a rosetta stone to help you translate them to APL :
https://sharpplot.com/Languages.htm
@Nic Well, we need to understand the pieces so we can construct out own charts. How do I draw f(x)=x²?
@Nic Trivial APL question: How does one surround it in a dfn?
 plot←{
     _←InitCauseway ⍬
     sp←⎕NEW Causeway.SharpPlot
     _←sp.DrawLineGraph ⍵
     View sp
 }
Gives: VALUE ERROR: No result was provided when the context expected one
Nic
Nic
Jun 16, 2020 2:47 PM
@AviF.S. Ah yes, there is this problem that InitCauseway and View are not result-returning
Adam discovered is last week and I've just uploaded the fix so you won't have it yet.
@Nic Ah! So we wait until the next release?
OK, somehow in the terp. I'm getting a VALUE ERROR on the ⎕NEW Causeway.SharpPlot
@AviF.S. You should be able to use the do operator from the dfns workspace to circumvent this.
@JeffZeitlin What's the terp?
Nic
Nic
There are a few nasty ways to call a non result-returning function in a dfn
one is : `_←⍎'InitCauseway⍬ ⋄ 1' ⍝ _←1`
Jun 16, 2020 2:48 PM
Avi: 17.1
@AviF.S. interpreter
@JeffZeitlin oop nvm?
@RichardPark Hahahaha, thanks!
@JeffZeitlin Ah? Why terp for 17.1?
do←{⍎'⍺⍺ ⍵ ⋄ ⍵' ⋄ ⍺⍺} and then _←InitCauseway do ⍬
"inTERPreter"
@JeffZeitlin Ah, it was that! Thanks!
Nic
Nic
Jun 16, 2020 2:50 PM
:54675710  plot←{
     _←⍎'InitCauseway ⍬ ⋄ 1'
     sp←⎕NEW Causeway.SharpPlot
     _←sp.DrawLineGraph ⍵
     _←⍎'View sp ⋄ 1'
     sp
 }
@Nic Ctrl+K (you can edit it and press that now)
Nic
Nic
I'm not proud of this
@Nic I have some time series data with only info from sporadic dates, what's best way to plot this?
plot←{
  do←{⍎'⍺⍺ ⍵ ⋄ ⍵' ⋄ ⍺⍺}
  _←InitCauseway do⍬
  sp←⎕NEW Causeway.SharpPlot
  _←sp.DrawLineGraph ⍵
  _←View so sp
  sp
}
Nic
Nic
- line graph but that would "hide" the missing data
- scatter plot
- risers (infinitely thin bars) see https://sharpplot.com/Risers.htm
Jun 16, 2020 2:53 PM
@Nic For this version you'd need one more ⍎⍕
 plots←{
     _←⍎'InitCauseway ⍬ ⋄ 1'
     sp←⎕NEW Causeway.SharpPlot
     _←⍎'sp.DrawLineGraph ⍵ ⋄ 1'
     _←⍎'View sp ⋄ 1'
     sp
 }
Nic
Nic
@Adám thanks, much less shameful =)
Although, then it returns 'mySharpPlot'... Who knows what that means...
Nic
Nic
@AviF.S. Correct. Oh my god, most SharpPlot functions are not result-retuning...
I mean, SharpPlot fundamentally is a state machine, not a functional library
@Nic Haha, no worries!
@Adám Here as well, I believe you mean:
Nic
Nic
You really write procedural scripts rather than functions
Jun 16, 2020 2:55 PM
 plot←{
     do←{⍎'⍺⍺ ⍵ ⋄ ⍵' ⋄ ⍺⍺}
     _←InitCauseway do ⍬
     sp←⎕NEW Causeway.SharpPlot
     _←sp.DrawLineGraph do ⍵
     _←View do sp
     sp
 }
@Nic Ah, makes sense
@Adám It's an incredibly elegant workaround though! Thanks a bunch!
Nic
Nic
@AviF.S. +1
@Nic Although I'm still unsure of what to do with the result:
'mySharpPlot'
The normal way actually plots something. This just returns the name
Nic
Nic
That's a SharpPlot instance, with a bunch of methods and properties.
You might draw another line graph, or any other kind of graph, or add some notes
And finally at some point you'll output the chart in some way to an image
sp.SaveSvg '/tmp/mychart.svg' Causeway.SvgMode.FixedAspect
Also, can't one simply end with:
`View do sp`
?
AHA! The explorer in the terp helped. Somehow, SharpPlot wasn't in a Causeway namespace, it was in the Root (#) namespace. ⎕NEW SharpPlot
Nic
Nic
Jun 16, 2020 2:58 PM
or, to render as an SVG text string to push to a websocket or anything :
svg←sp.RenderSvg Causeway.SvgMode.FixedAspect
@JeffZeitlin I also have this when I )copy sharpplot
@RichardPark - I got this with )load sharpplot
Nic
Nic
@AviF.S. yes you may
@JeffZeitlin same difference
@Nic but what about the function returning mySharpPlot rather than displaying anything?
View isn't doing it when within dfn
Jun 16, 2020 3:00 PM
@AviF.S. You can View plot data
Nic
Nic
@AviF.S. I usually do that because when doing complex chart you usually have functions that do separate steps of work on the SharpPlot instance. Hence you want to return it to keep working on it.
But again if you're happy just to view the chart that's fine
@Nic Ah, of course, thanks!
Nic
Nic
@RichardPark Can you give us the data so that we actually do it ?
@RichardPark ? View plot ... doesn't return anything, so it is better. But it still doesn't graph anything either
Nic
Nic
Does anyone have some data to chart ?
Or should I proceed with some fake examples that I prepared
Or does anyone have some question about how to embed charts in whatever they want
Jun 16, 2020 3:05 PM
@all Odd, when I started a new window/session and reloaded sharpplot in it plotted just fine
@Nic There was a bug though, where it all returned and ran fine, but it simply stopped pulling up the plotted window...
Nic
Nic
@AviF.S. Are you using the RIDE ? If so, there can only be one window, and it doesn't pop up. When you plot a second chart, it silently redraws over the previous one
@Nic Afraid not it was a hypothetical thing, but I can make up some data - let's put ⎕TS-style timestamps in there as well
Nic
Nic
@RichardPark Yes, you'll have to convert it to International Day Number with
+2 ⎕NQ '.' 'DateToIDN' ⎕TS
@Nic Understood! Thanks! The window got hidden
Nic
Nic
@AviF.S. If you want multiple charts displayed, unfortunately you'll have to save the SVG to a file, and ]open it
Jun 16, 2020 3:09 PM
@Nic What about the grid?
Nic
Nic
That's a restriction of 3500⌶ (the RIDE html display that the View function uses)
@Nic Doesn't bother me!
Nic
Nic
@RichardPark what grid are you talking about ?
@Nic There's some sharpplot thing I saw that lets you plot multiple charts?
Nic
Nic
@RichardPark yes, there are several strategies to doing multiple plot : sharpplot.com/Multiplots.htm
depending on the level of customisation that you need
That page should give you a lot to think about =)
Jun 16, 2020 3:13 PM
@Nic Okay thanks - this: sharpplot.com/Multiples.htm was what I remembered
Regarding datasets, kaggle.com/datasets
Nic
Nic
@RichardPark yes, that's the simplest kind, when all charts are identical
My made up date series: ↑(date¨43578+?20⍴100)(('Groceries' 'Entertainment' 'Subscription')[?20⍴3])(20+?20⍴100)
No specific recommendation tho
@Nic Ah I see
Nic
Nic
Jun 16, 2020 3:14 PM
@RichardPark please provide the date function
@Nic )copy dfns date days
@Nic Sorry! )copy dfns date
@Adám +1
Nic
Nic
@RichardPark Ah right. For sharpplot you want to keep the IDN rather than convert them to timestamps.
SharpPlot uses OLE dates which are one-off to IDN if I remember correctly (because of no Feb 29th in 1900)
@Nic Yeah but I'm imagining I have human-readable dates as input
Nic
Nic
@RichardPark ok let me work it out
Jun 16, 2020 3:16 PM
@Nic What I pasted is just to generate random data
(For the uninitiated, IDN is the International Day Number ― the number of days since the beginning of 1899-12-31.)
This dataset looks relatively straightforward? kaggle.com/sudalairajkumar/daily-temperature-of-major-cities
Nic
Nic
@Richard :
Richard size;count;date;dates;oledates;sp;type
'date'⎕CY'dfns'
dates←date¨43578+size?10×size
type←'Groceries' 'Entertainment' 'Subscription'[?size⍴3]
count←20+?size⍴100

oledates←{1+2 ⎕NQ'.' 'DateToIDN'⍵}¨dates ⍝ OLE dates are 1 more because Microsoft thought there was a Feb 29th, 1900
InitCauseway ⍬
sp←⎕NEW Causeway.SharpPlot
sp.SplitBy⊂type ⍝ single argument must be enclosed
sp.ScatterPlotStyle←Causeway.ScatterPlotStyles.(GridLines+Risers)
sp.SetColors System.Drawing.Color.(Blue Red Green)
Try :
Richard 20
You might want to set sp.XAxisStyle←Causeway.XAxisStyles.(Date+MonthlyTicks)
@Nic Apart from having to remove all the "Causeways" because I copied sharpplot to #, I got Undefined name: System', then did ⎕USING←'' and now have Undefined name: Drawing`
Nic
Nic
@RichardPark Right, working around the InitCauseway mechanism is a bit brave. Do not set ⎕USING. Just remove every "Causeway." and "System.Drawing."
Jun 16, 2020 3:32 PM
@Nic Okay let's try that - I just tried )clear and it got up to saving SVG and got DOMAIN ERROR on ColorIsCmyk[2] alpha←⌊colour÷16777216
Nic
Nic
However I recommend sticking to the InitCauseway approach because code is then :
- cross platform (Linux VS Windows .Net)
- more similar to the C# samples in sharpplot.com
but I will try again
@Nic What is the normal way of loading sharpplot then?
Nic
Nic
@RichardPark Call InitCauseway and do not remove the Causeway. and System.Drawing.
@Nic Yeah I mean before that: )copy sharpplot?
Nic
Nic
@RichardPark I ususpect that's because you've set ⎕USING
Jun 16, 2020 3:33 PM
@Nic but I hadn't before
Nic
Nic
no, the passphrase is :
'InitCauseway' 'View'⎕CY'sharpplot'
Then from there just call the script
@Nic hmmmmm
@Nic from a clear ws?
Nic
Nic
@RichardPark from whereever you like.
As in:
'InitCauseway' 'View'⎕CY'SharpPlot'
Richard 20
'InitCauseway' 'View'⎕CY'SharpPlot'
Richard 20
VALUE ERROR: Undefined name: Causeway
Richard[8] sp←⎕NEW Causeway.SharpPlot
Nic
Nic
yup
PS ⎕CY'sharpplot' should be lower case for compatibility with linux.
However I don't know what's wrong in your case
Jun 16, 2020 3:39 PM
@Nic You said 14.0? I'm gonna try it in 15
Nic
Nic
@RichardPark Ah ! you're using 14.0 ! You deperately need to update sharpplot.dws
No I've been using 17.1
@Nic I was wondering if I've got some funny setting, but I know my 15.0 is all defaults, I don't have a 14.0 installed currently
Nic
Nic
@RichardPark does it still fail after a )clear and a copy paste from my post ?
Nic
Nic
@RichardPark That's fine : the later interpreter the better
@RichardPark Which OS ?
Jun 16, 2020 3:41 PM
@Nic Win 10
@Nic As I think I said, removing Causeway gets me most of the way
@Nic Yep, successfully plots with:
)copy sharpplot
Nic
Nic
OMG there is a bug in InitCauseway =(
remove Causeway and System.Drawing.Color
Richard 20
Nic
Nic
The fix is to de-localise ⎕USING in InitCauseway.
@Nic ooooh
Nic
Nic
And I forgot an ⊂ before the argument to SetColors =(
Jun 16, 2020 3:46 PM
@Nic OOOHHH!!!
@Nic And! And!
@Nic Delocalising ⎕USING in InitCauseway has also fixed the thing (can't remember when I first noticed / started ignoring it) where it would say "no in memory viewer available - saving temporary SVG..."
Nic
Nic
Richard size;count;date;dates;oledates;sp;type
'date'⎕CY'dfns'
dates←date¨43578+size?10×size
type←'Groceries' 'Entertainment' 'Subscription'[?size⍴3]
count←20+?size⍴100

oledates←{1+2 ⎕NQ'.' 'DateToIDN'⍵}¨dates ⍝ OLE dates are 1 more because Microsoft thought there was a Feb 29th, 1900
InitCauseway ⍬
sp←⎕NEW Causeway.SharpPlot
sp.SplitBy⊂type ⍝ single argument must be enclosed
sp.ScatterPlotStyle←Causeway.ScatterPlotStyles.(GridLines+Risers)
sp.SetColors⊂System.Drawing.Color.(Blue Red Green)
sp.SetMarkers Causeway.Marker.Bullet
(definite version)
@Nic Perfect +1
@Nic - So you're saying that I should delete ⎕USING from line 0 in InitCauseway?
@Nic I shall save it for a rainy day (it's raining outside)
Nic
Nic
@JeffZeitlin Yes, otherwise it fails on windows. The next version of sharpplot will have it fixed
Jun 16, 2020 3:51 PM
OK, got it.
Nic
Nic
Any other question ?
Since this ended up derailing the lesson, I suggest continuing in weeks.
Nic
Nic
How do I embed the SVG file to display the resulting graph ?
@Nic You have to render it as png first. Easiest is to open in a browser, screenshot, go to imgur.com/upload then paste, wait, right-click and view image, copy url, and pase only the url into a separate message here.
Jun 16, 2020 3:59 PM
Looking good :)
@Nic Thank you Nic
@Nic Are you up for continuing in two weeks?
Nic
Nic
Notice the use of SplitBy. Pretty powerful. sharpplot.com/SharpPlot-SplitBy.htm
@Adám Yup.
OK, then let's call it a day. Thank you to the participants, and especially thank you to Nic for coming in and running this. See you in two weeks!
Does the existence of SharpPlot mean that RainPro is "deprecated" in terms of being a recommended plotter for Dyalog APL?
I ask because the latter is documented in the Mastering Dyalog APL book.
Jun 16, 2020 4:04 PM
@ab5tract Yeah, SharpPlot is the recommended method now.
Nic
Nic
@ab5tract Yes. In fact, SharpPlot is a deep refactoring of RainPro.
And much better documented
Although the API is a little bit too large, but that's because of history
Nice great to know
@Nic Is there APL specific documentation?
Nic
Nic
@ab5tract Unfortunately not. All the samples are in C#. You can refer to sharpplot.com/Languages.htm to help you translate them to APL, which is pretty straightforward.
You can also find pure-APL scripts in the Samples namespace of the SharpPlot workspace
Right, because it's just the typical .Net OO glue I guess?
@Nic Great tip!
@Nic Does the .NET APL code work with Core?
Nic
Nic
Jun 16, 2020 4:07 PM
@ab5tract Yup, and as long as you just set properties and call methods, all languages look the same. The only pitfall is to enclose a single argument, otherwise it's taken as an array of arguments.
@Nic I suppose one could just get used to always putting between methods and arguments?
Nic
Nic
@ab5tract just )load sharpplot and it will show you how to use the scripts
@Adám Unfortunately not because it's not all strings. You have shallow and deep numeric arguments too. sometimes scalars.
@Nic Ah, I guess the one case that'll fail is when you have multiple numeric scalar arguments.
@Nic Got it, thanks!
Nic
Nic
Have to run. See you around, guys !
Jun 16, 2020 4:12 PM
Take care
 
Conversation ended Jun 16, 2020 at 16:12.