Building a wrapper around Matlibplot for visualizations

I can’t find a great visualization library for Scala.

It seems like it’d be pretty easy to write a wrapper library around python’s Matlibplot. Let the user set the path to their python binary, and provide their data using an api similar to Matlibplot.

Behind the scenes, build a string which is the python code needed to display the visualization. At ‘plot.show()’, pass that string to the python binary, and have the visualization show up.

Yes, its hacky, but its a pretty good / easy way to have great visualizations in Scala without having to dive into python, or doing all that work from scratch.

Thoughts?

If you want to interop with Python perhaps have a look at https://scalapy.dev/

2 Likes

Take a look at https://github.com/RussP/scalars

It’s more than just plotting, but you are free to just use the plotting part of it, of course.

Physical Scalars and Plotting Tools in Scala

An open-source scalar package and associated software tools have been developed in the Scala programming language, including plotting tools based on the free GRACE plotting package. The scalar package represents physical scalars and can help to prevent errors involving physical units in engineering and scientific computation. The scalar package includes a complete implementation of the standard SI metric system of units and many common non-metric units. The design also allows users to easily define a specialized or reduced set of physical units for any particular application or domain. The scalar package can be used in two different modes: one mode provides unit compatibility checking but is slower, and the other mode bypasses the compatibility checks but is much faster and still prevents the most common type of unit error. Switching between the two modes requires no changes in the user’s code, making it convenient and usable with no significant performance penalty for even the most computationally intensive applications.

I’ve been working on a plotting library for Scala called SwiftVis2 (https://github.com/MarkCLewis/SwiftVis2), but it is still very much a research project. The fact that it isn’t in a Maven repository would make it hard to use at this point. However, in working on it I’ve looked into the other options and the two best ones seem to be EvilPlot (https://cibotech.github.io/evilplot/) and NSPL (https://pityka.github.io/nspl/). If you only want web-based plotting, Vegas-Viz (https://github.com/vegas-viz/vegas-viz.github.io) might also be an option. It is what Polynote chose for their default Scala plotting option, but me experience trying to use it on anything other than the web has not been good.

None of the Scala options are nearly as mature as Matplotlib, but if any of them can do what you need I would suggest going with them as that helps them get a user base that can aid them becoming mature.

(As a side note, my fun task today was adding the ability to do rendering with SwiftVis2 in a React app using Slinky. We now support rendering with SVG, JavaFX, Swing, Scala.js Canvas, Scala.js React, and Scala Native using SDL2. The Native rendering isn’t as functional as the others, but the others handle a lot of functionality.)

1 Like

My plotting package above is based on a free plotting package called GRACE, which is quite mature (although active development ended a few years ago). I started using it many years ago for plotting, and I slowly developed a sort of reverse-engineered Scala API for it to enhance my productivity. It’s a bit of a hack perhaps, but it does the job for me. You can see examples of resulting plots (in pdf) that I genereated for my work in automated ATC here:

http://russp.us/plots/

Here is the GRACE website:

https://plasma-gate.weizmann.ac.il/Grace/

Grace is a WYSIWYG 2D plotting tool for the X Window System and Mtif. Grace runs on practically any version of Unix-like OS. As well, it has been successfully ported to VMS, OS/2, and Win9/NT/2000/XP (some minor functionality may be missing, though).

GRACE works on Windows and Mac but is more naturally at home on Linux. If I had more time and knew more about graphical programming, I’d consider porting it from Motif to a more modern windowing system. I really have no idea what to use and how difficult that would be, however. Does anyone have any ideas about that?

1 Like

Here is my somewhat (very?) immature plotting library for Scala.

In README.md there is a script that you can paste in ammonite shell and see it plot some parametric curve. Right mouse button click gives you minimal context menu.

There is also slightly out of date documentation site
https://splot-web.github.io/

1 Like