• Stars
    star
    179
  • Rank 214,039 (Top 5 %)
  • Language
    Nim
  • License
    MIT License
  • Created over 6 years ago
  • Updated 8 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

plotly wrapper for nim-lang

nim-plotly: simple plots in nim

Docs plotly CI

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 is not specifically for the javascript nim target (but the javascript target is supported!).

Internally, it serializes typed nim datastructures to JSON that matches what plotly expects.

Examples

See a collection of real-world examples in the wiki

Simple Scatter plot

import plotly
import chroma

var 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()

simple scatter

The show call opens a browser pointing to a plot like above, but the actual plot will be interactive.

Scatter with custom colors and sizes

source

sizes and colors

Multiple plot types

source

multiple plot types

Stacked Histogram

source

stacked histogram

Other examples

in examples

Note about C & JS targets / interactive plots

The library supports both the C as well as Javascript targets of Nim. In case of the C target, the data and layout is statically parsed and inserted into a template Html file, which is stored in /tmp/x.html. A call to the default browser is made, which loads said file. The file is deleted thereafter.

This static nature has the implication that it is not possible to update the data in the plots. However, thanks to Nim's ability to compile to Javascript, this can still be achieved if needed. When compiling to the JS target the native plotly functions are available, including react and restyle, which allow to change the data and / or layout of a plot defined in a div container. See the fig8_js_interactive.nim for such an example.

Note about plotly under Windows Subsystem for Linux (WSL)

Starting from version v0.3.0 of plotly, WSL is supported. This requires the user to define the BROWSER environment variable and assumes the user wishes to use a normal Windows browser.

When setting the BROWSER variable, make sure to handle the possible spaces (e.g. if browser installed in Program Files) by either escaping spaces and parenthesis with a backslash or just putting the whole path into quotation marks. E.g:

export BROWSER="/mnt/c/Program Files (x86)/MyBrowserCompany/Browser.exe"

to set the variable for the local session.

TODO

  • 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 of nim-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.

More Repositories

1

Datamancer

A dataframe library with a dplyr like API
Nim
130
star
2

Unchained

A fully type safe, compile time only units library.
Nim
110
star
3

numericalnim

A collection of numerical methods written in Nim
Nim
87
star
4

flambeau

Nim bindings to libtorch
Nim
84
star
5

getting-started

Getting started with Nim for Scientific Computing
Nim
61
star
6

nimjl

A bridge between Nim-lang and Julia !
Nim
49
star
7

nimcuda

Nim bindings for CUDA
HTML
42
star
8

nimblas

BLAS for Nim
Nim
42
star
9

scinim

The core types and functions of the SciNim ecosystem
Nim
37
star
10

theo

Theo is an optimized bigint and number theory library for Nim
Nim
26
star
11

rnim

A bridge between R and Nim
Nim
24
star
12

freccia

Apache Arrow implementation in Nim
Nim
22
star
13

Measuremancer

A library to handle measurement uncertainties & error propagation
Nim
21
star
14

nimcl

High level wrapper over OpenCL
Nim
19
star
15

nimfftw3

Nim bindings for FFTW3.
Nim
18
star
16

astGrad

Symbolic differentiation based on the Nim AST
Nim
17
star
17

impulse

Impulse will be a collection of primitives for signal processing (FFT, Convolutions, ...)
Nim
16
star
18

nimlapack

LAPACK bindings for Nim
Nim
16
star
19

vectorize

SIMD vectorization backend
Nim
15
star
20

nim-constants

Mathematical numerical named static constants useful for different disciplines
Nim
13
star
21

polynumeric

A nim module to handle polynomials
Nim
12
star
22

xrayAttenuation

A library to compute transmission / absorption of X-rays through matter
Nim
10
star
23

bio

A library to work with biological sequences.
Nim
7
star
24

fmu.nim

create your own multiplatform FMU (Functional Mock-up Interface) models with Nim
Nim
6
star
25

horizonsAPI

API for the JPL Horizons tool to retrieve solar system parameters
Nim
5
star
26

symengine.nim

A Nim wrapper of SymEngine
Nim
5
star
27

Arrayfire-Nim

Fork of https://github.com/bitstormFA/ArrayFire-Nim
Nim
5
star
28

runtimeGrad

A playground for different runtime based automatic differentiation implementations
Nim
4
star
29

netcdf

NetCDF bindings for Nim
Nim
2
star
30

mcpl

A wrapper for the Monte Carlo Particle Lists (MCPL) library
Nim
2
star
31

mclimit

A Nim port of the mclimit confidence limit computation library
C++
1
star