- Notifications
You must be signed in to change notification settings - Fork15
plotly wrapper for nim-lang
License
SciNim/nim-plotly
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
This is a functioning plotting library. It supports,line (with fill below),scatter (with errors),bar,histogram,heatmap,candlestick and combinations of those plot types. More standard types can be added on request.
This isnot specifically for the javascript nim target (but thejavascript target is supported!).
Internally, it serializes typednim
datastructures to JSON that matches whatplotly expects.
See a collection of real-world examples in thewiki
import plotlyimport chromavar colors=@[Color(r:0.9, g:0.4, b:0.0, a:1.0),Color(r:0.9, g:0.4, b:0.2, a:1.0),Color(r:0.2, g:0.9, b:0.2, a:1.0),Color(r:0.1, g:0.7, b:0.1, a:1.0),Color(r:0.0, g:0.5, b:0.1, a:1.0)]var d=Trace[int](mode:PlotMode.LinesMarkers, `type`:PlotType.Scatter)var size=@[16.int]d.marker=Marker[int](size:size, color: colors)d.xs=@[1,2,3,4,5]d.ys=@[1,2,1,9,5]d.text=@["hello","data-point","third","highest","<b>bold</b>"]var layout=Layout(title:"testing", width:1200, height:400, xaxis:Axis(title:"my x-axis"), yaxis:Axis(title:"y-axis too"), autosize:false)var p=Plot[int](layout:layout, traces:@[d])p.show()
Theshow
call opens a browser pointing to a plot like above, but the actual plot willbe interactive.
The library supports both theC
as well asJavascript
targets ofNim. In case of theC
target, the data and layout is staticallyparsed and inserted into a template Html file, which is stored in/tmp/x.html
. A call to the default browser is made, which loads saidfile. The file is deleted thereafter.
This static nature has the implication that it is not possible toupdate the data in the plots. However, thanks to Nim's ability tocompile to Javascript, this can still be achieved if needed. Whencompiling to theJS
target the native plotly functions areavailable, includingreact
andrestyle
, which allow to change thedata and / or layout of a plot defined in adiv
container. See thefig8_js_interactive.nim
for such an example.
Starting from versionv0.3.0
of plotly, WSL is supported. Thisrequires the user to define theBROWSER
environment variable andassumes the user wishes to use a normal Windows browser.
When setting theBROWSER
variable, make sure to handle the possiblespaces (e.g. if browser installed inProgram Files
) by eitherescaping spaces and parenthesis with a backslash or just putting thewhole path into quotation marks. E.g:
export BROWSER="/mnt/c/Program Files (x86)/MyBrowserCompany/Browser.exe"
to set the variable for the local session.
- add .show() method to plot which looks for and opens a browser (similar to python webbrowser module)
- support multiple axes (2 y-axes supported).
- experiment with syntax for multiple plots (https://plot.ly/javascript/subplots/ or use separate divs.)
- better side-stepping ofnim-lang/Nim#7794
- convert
%
procs into macros so I don't have to re-write the same code over and over. - more of plotly API
- ergonomics / plotting DSL
- custom interactivity.
About
plotly wrapper for nim-lang