Conversation started Jun 30, 2020 at 14:32.
Jun 30, 2020 14:32
Well, welcome to APL Cultivation.
Nic is going to continue the previous lesson on simple plotting.
@Adám But what about which extension is more useful/practical? I don't imagine the other one is very difficult to self-define either, esp. with new quad casing
Whoops! Sorry to interrupt! Will put on hold for later
Nic
Nic
So to set up your environment for charting, do:
'InitCauseway' 'View' ⎕CY 'sharpplot' ⋄ InitCauseway ⍬
Then you can start plotting by doing something along the lines of :
sp←⎕NEW Causeway.SharpPlot
sp.DrawLineGraph ⊂1 3 2 5 4
View sp
Don't forget backticks or Ctrl+K for monospace.
Nic
Nic
you should get something along the lines of
https://i.imgur.com/Blo0VAS.png
Yup. Works for me.
RGS
RGS
Jun 30, 2020 14:40
@Nic VALUE ERROR: Undefined name: Causeway? is this something that was troubleshot during last time? Can I use 18.0 for this?
Nic
Nic
@RGS Yes, there is a bug on Windows that we discovered last time =(
You have to de-localise ⎕USING in the InitCauseway function that you brought in
Unfortunately the bug was discovered after the 18.0 release
RGS
RGS
works now, thanks
Nic
Nic
Now's the time to ask questions.
I guess the interesting bit is how to embed charts in <whatever you're trying to do>
We might also discuss which chart type is appropriate for which data (if you have data to submit)
RGS
RGS
@Nic is this sharpplot-specific? or is it the general principles of data visualization you are talking about? or what do you mean?
Nic
Nic
This is more general, hence less appropriate for this chat room. But if there are no other questions, let's do it !
RGS
RGS
Jun 30, 2020 14:48
I have one question
is there a nice utility function to save my graph without having to View it first?
Nic
Nic
SharpPlot is greatly influenced by Tufte's recommendations ( en.wikipedia.org/wiki/Edward_Tufte )
Yes, View is usually for development. Once you're happy with the chart, you can output it to file by doing
`sp.SaveSvg '/tmp/chart.svg' Causeway.SvgMove.FixedAspect
You can also grab the svg source directly in APL (without writing to file) by doing
sp.RenderSvg Causeway.SvgMode.FixedAspect
RGS
RGS
afaiac you can move on to discussing other things, not sure if you were waiting for me @Nic ..? The functions you mentioned worked, ofc
Nic
Nic
I don't have a story to tell. If I wanted to provide general guidelines about chart that would be a webinar.
Do you have no questions ?
I can also show a little function I wrote to plot the Covid data from a live data feed
RGS
RGS
@Nic I guess that'd be nice
Nic
Nic
Jun 30, 2020 15:04
{sp}←OwidCovidData;Causeway;Drawing;InitCauseway;System;View;cdata;cfields;codes;countries;countries_to_plot;csv;data;date;dates;emptyrow;fdata;field;fields;fields_to_plot;location;locations;miss;numfields;row;sp;txtfields;values
miss←¯1E300 ⍝ missing value

⎕SE.SALT.Load'HttpCommand'
csv←(HttpCommand.Get'https://covid.ourworldindata.org/data/owid-covid-data.csv').Data
csv←⎕CSV csv'S'
fields←csv[1;] ⋄ csv←1↓csv
txtfields←'iso_code' 'continent' 'location' 'date' 'tests_units'
date←csv[;fields⍳⊂'date']
In a proper application, there would be two functions : one to build the data from source, one to plot it. But I thought it would be simpler to have a single big function here
You should get something like that :
Nic
Nic
Jun 30, 2020 15:25
I you want an overview of SharpPlot and of the available chart types, you can also look at :
https://dyalog.tv/Dyalog13/?v=Xo3vRQMaPxo
And for the documentation : sharpplot.com
RGS
RGS
@Nic Thanks for the links ○/
Nic
Nic
The amount of questions makes me think that we're done with charting aren't we ?
@Nic Or people are just busy. How about some simple examples of combining options?
Nic
Nic
Simple examples for each chart type : sharpplot.com/Charts.htm
If you don't have "real" questions, you might as well the browse the doc
RGS
RGS
from the docs, "five common vector formats (SVG, PDF, EPS, XAML, EMF, VML)" but the list in () has 6 formats. Are any 2 of those basically the same or is this an error?
Nic
Nic
Jun 30, 2020 15:29
It's a typo =)
Actually it's only half a typo because VML has been abandoned by Microsoft decades ago and now has no support whatsoever
I'm a little confused about the date handling. Do we have to convert to a serial number to get proper spacing?
Nic
Nic
@Adám Do you mean the fact that some ticks don't have labels ? That's to avoid label collision. The easy fix is to use angled labels ( sharpplot.com/AngledLabels.htm )
RGS
RGS
(@Nic I wish I had a/some good question/s but nothing other than "how do I configure ___" comes to mind :/ )
Nic
Nic
@RGS Sure. All the suffering in the charting industry comes from the vast world of possible configurations.
@Nic No, I mean if I have a bunch of dates or even date-times in vector format (Y M D or Y M D h m s f) as my X values, what do I need to do to make them position correctly on the axis.
RGS
RGS
Jun 30, 2020 15:36
@Nic Actually one thing comes to mind but it isn't really charting... Can one "hack" the sharpplot to make "drawings"? e.g. is there a plot type that allows me to specify the colour of 2d (square/rectangular) regions?
Nic
Nic
@Adám I don't get it. Can you show me a repro ?
@Nic How do I plot a line graph of:
  dates←(2020 1 1)(2020 1 31)(2020 2 1)
  values←3 1 4
Nic
Nic
Adam;Causeway;System;dates;sp;values
dates←(2020 1 1)(2020 1 31)(2020 2 1)
values←3 1 4

dates←1+{2 ⎕NQ'.' 'DateToIDN'⍵}¨dates ⍝ 1+ because microsoft invented 1900-02-29

'InitCauseway' 'View'⎕CY'sharpplot'
InitCauseway ⍬
sp←⎕NEW Causeway.SharpPlot
sp.XAxisStyle←Causeway.XAxisStyles.Date
sp.XDateFormat←'dd-MMM-yy'
sp.DrawLineGraph values dates

View sp
RGS
RGS
@Nic thanks!
Nic
Nic
@RGS you can add a Y-zone in Adam's graph by doing
sp.SetYZones ⎕NEW Causeway.Zone(2 3 System.Drawing.Color.Orange Causeway.FillStyle.GradientTop)
before the sp.DrawLineGraph
Jun 30, 2020 15:43
@Nic OK, then the answer is "Yes", we do need to convert to a serial number. However dates←33 ⎕DT dates is much easier now :-)
Or golf it: dates⎕DT⍨←33
Nic
Nic
@Adám Ah I get it now. it's "serial number" that I didn't undersrtand.
in .Net you can also use System.DateTime.ToOADate
https://docs.microsoft.com/en-us/dotnet/api/system.datetime.tooadate?view=netcore-3.1
RGS
RGS
@Nic interesting
Nic
Nic
which, again, is 1+International Day Number
RGS
RGS
Why doesn't it work after the DrawLineGraph?
Nic
Nic
@RGS That's because SharpPlot is fundamentally a state machine. Its philosophy is that of PostScript. 1. Set up paramaters 2. draw 3. back to step 1
It's not possible to "undo" something
It may appear old-fashioned in the days of OO API, but it's in fact VERY powerful.
Jun 30, 2020 15:47
@Nic Yeah, that's what 33 means.
Nic
Nic
Have a look at sharpplot.com/Multiplots.htm to see how powerful state machines can be.
You can't do these kind of things with OO charting packages - unless they have a much more complex API - which is then probably largely undocumented - e.g. Syncfusion
Shall we call it a day ?
Yeah, I think so. Thank you so much, Nic!
Any ideas for the next lesson?
Nic
Nic
You're welcome. If you need any more help with charting, don't hesitate to ask : nicolas at dyalog dot com
 
Conversation ended Jun 30, 2020 at 15:53.