Library to create top-notch plots directly within NodeJS on top of plotly.js without any front-end preparations. Inspired by matplotlib.
npm install nodeplotlib# oryarn add nodeplotlib
If ES5 use
require() instead of
import. Here is a short animation about howto and the results.
Since Python provides with matplotlib a library for spawning plot windows, NodeJS isn't by default. But there are awesome plotting libraries for usage in front-end. So this lib targets people like scientists who easily want to create beautiful plots in a time-saving way.
The library provides a simple interface with (for now) just three functions. A
stack and a
clear function. The
plot() functions spawns a plot to the browser, if a plotdata is given as an
argument. Otherwise it plots all the
stack()ed plotdata. The arguments are of type
Plot, which is a
partial of plotly's
PlotData type. With the
clear() function the stack container can be cleared.
With the stack function the user is able to print multiple charts on one page.
The plot function plots all stacked plots and the plot given by parameter (if there is one).
Afterwards the temporary container gets cleared and you can call
without any predefined plots.
The functions are of the form:
;plotdata?: Plot, layout?: Layout: void;stackdata: Plot, layout?: Layout: void;clear: void;
In this section there are some examples to getting started. See the full plotly cheatsheet.
3D Line Plots
3D Surface Plots
In order to style the plot, one is able to pass in the
layout parameter, which internally
Partial<Layout> from plotly's
Layout. See the full layout documentation
With this parameter one is able to define styles like title, axis labels, subplots and many more.
|Simple charts||Advanced charts||3D Plots|
|Scatter||2d density plots||Scatter|
|Pie charts||Contour plots|
Behind the scenes
The lib launches a webserver and opens new tabs for every plot located at
http://localhost:8080/plots/:id. At this address a temporary html template
file, the nodeplotlib script and plotly.min.js are available. The client side
js requests the plot data at
http://localhost:8080/data/:id. After all
pending plots are opened in a unique tab and all the data is requested, the
server shuts down. If you fire another plot the server starts again provides
your plot and shuts down automatically.
Another port can be provided via PORT environment variable.
Contributions in all forms are welcome.
Fork the Github repository and clone
it to your PC. Install the npm dependencies using the
install command. It installs
the dependencies and copies plotly types to project source. These won't affect
the git tree.
It would be nice to make the library compatible with Observable-streams and update the plots in real-time.
Get in touch
Hi, I am Felix, Software developer and Angular, NgRX contributor
If you like this library, think about giving it a star or follow me on twitter or github or check out my personal the website.