Create publication-ready 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 Plotly.js
PlotData. With the
clear() function the stack container can be cleared.
The following snippet provides an 'reallife' example with tensorflow to get an idea of its simplicity and how to use it.
;;// Just import plot;;model.addlayers.dense;model.compile;;;;;// Spawn a plot in your browserplot;
With the stack function the user is able to print multiple charts on one page (e.g. three times the same plot).
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?: Partial<PlotData>, layout?: Partial<Layout>, cb?: Function: void;stackdata?: Partial<PlotData>, layout?: Partial<Layout>: void;clear: void;
In order to style the plot, one is able to pass in the
layout parameter. With it
one is able to define styles like title, axis labels, subplots and many more.
Plotly.js provides a nice example for radial plots. Just pass in the plotly.js data
plot() function and spawn radial plots.
Plotly.js plot types
For the different plot types have a look at the Plotly.js documentation. It provides
|Simple charts||Advanced charts|
|Scatter Plots||2d density plots|
|Pie Charts||Contour plots|
Any many more different plottypes.
Behind the scenes
The lib launches an express webserver and opens new tabs for every plot located
http://localhost:8080/plots/:id. The client side js requests the plot data
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.
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.