For details, see How to Use.
Plotting Arrays on a 2D Graph
This VCSSL program plots the contents of arrays containing coordinate values on a 2D graph. It's a short sample code, making it a good starting point for modification or reuse.
In graph plotting for numerical computations and similar tasks, it’s common to first output coordinate values to a file from a computation program, and then plot them by reading the file. However, writing to and reading from files takes some time, so it can become a bottleneck when you want to create animations.
In such cases, you can achieve faster plotting by directly transferring the coordinate values stored in arrays to the graph software without using files.
» Related Page: 2D Graph Plotting in Java
Sponsored Link
How to Use
Download and Extract
At first, click the "Download" button at the above of the title of this page by your PC (not smartphone). A ZIP file will be downloaded.
Then, please extract the ZIP file. On general environment (Windows®, major Linux distributions, etc.), you can extract the ZIP file by selecting "Extract All" and so on from right-clicking menu.
» If the extraction of the downloaded ZIP file is stopped with security warning messages...
Execute this Program
Next, open the extracted folder and execute this VCSSL program.
For Windows
Double-click the following batch file to execute:
For Linux, etc.
Execute "VCSSL.jar" on the command-line terminal as follows:
java -jar VCSSL.jar
» If the error message about non-availability of "java" command is output...
After Launching
When the program is launched, it starts the 2D graph software and plots the contents of an array filled with calculated coordinate values.
To change the plotted data, modify the part of the code that fills the coordinate arrays (inside the "for" loop).
Code
Now, let's go through the code of this program. It is written in VCSSL.
Full Code
Here is the complete code:
The flow is simple: the first half fills the arrays with sample coordinate values, and the second half plots them on the graph.
First Part
Let's take a look at the beginning of the code:
The line "coding UTF-8;" specifies the character encoding used in the program (you can also use Shift_JIS, etc.). This line is optional, but including it helps prevent character corruption.
The line "import tool.Graph2D;" loads the tool.Graph2D library, which is necessary to work with 2D graphs.
Preparing Sample Coordinate Arrays
Next is the part where the sample coordinate values are stored in arrays:
This code creates two arrays, "xData" and "yData", each with 11 elements to store coordinates. It stores 11 coordinate points for the function "y = x * x", for values of x from 0 to 10.
Compared to the previous example that wrote the coordinates to a file assigning values directly to arrays is much faster. This approach is especially useful when you want to animate the graph -- plotting from arrays instead of files results in much smoother performance.
Plotting
Finally, here is the part that plots the prepared data on the 2D graph:
The newGraph2D() function launches the 2D graph software. Each time you call this function, a new graph window is opened and assigned a unique ID number.
For example, if you launch multiple graph windows, they may be assigned IDs like Graph #12, #22, #101, etc. In this case, the ID is stored in the int variable "graph".
Next, the setGraph2DData() function is used to plot the arrays xData and yData on the 2D graph that was just launched. The first argument specifies the graph ID -- the same one received when the graph was started. Even with multiple graphs open, you can specify which one to operate on using the ID.
License
The license of this VCSSL / Vnano code (the file with the extension ".vcssl" / ".vnano") is CC0 (Public Domain), so you can customize / divert / redistribute this VCSSL code freely.
Also, if example code written in C/C++/Java are displayed/distributed on Code section of this page, they also are distributed under CC0, unless otherwise noted.
3D Graph Plotting Tool for Animating Data Loaded from Multiple Files |
|
![]() |
A simple tool which plots 3D animation graphs by loading multiple data files. |
2D Graph Plotting Tool for Animating Data Loaded from Multiple Files |
|
![]() |
A simple tool which plots 2D animation graphs by loading multiple data files. |
3D Graph Tool for Plotting & Animating Expressions of the Form of "z = f(x,y,t)" |
|
![]() |
A simple tool which plots the expression (formula) of the form of "z = f(x,y,t)" to the 3D graph, and plays it as animation. |
2D Graph Tool for Plotting & Animating Expressions of the Form of "y = f(x,t)" |
|
![]() |
A simple tool which plots the expression (formula) of the form of "y = f(x,t)" to the 2D graph, and plays it as animation. |
3D Graph Tool for Plotting & Animating Parametric Expressions of the Form of x(t), y(t), z(t) |
|
![]() |
A simple tool which plots parametric expressions (formulas) of the form of x(t), y(t), z(t) to the 3D graph, and plays it as animation. |
2D Graph Tool for Plotting & Animating Parametric Expressions of the Form of x(t) and y(t) |
|
![]() |
A simple tool which plots parametric expressions (formulas) of the form of x(t) and y(t) to the 2D graph, and plays it as animation. |
3D Graph Tool for Plotting Expressions of the Form of "z = f(x,y)" |
|
![]() |
A simple tool which plots the expression (formula) of the form of "z = f(x,y)" to the 3D graph. |
2D Graph Tool for Plotting Expressions of the Form of "y = f(x)" |
|
![]() |
A simple tool which plots the expression (formula) of the form of "y = f(x)" to the 2D graph. |
Animating a 3D Graph by Continuously Plotting Arrays (Surface/Mesh Plot) |
|
![]() |
Explains how to create 3D surface/mesh graph animations by updating arrays over time. |
Animating a 3D Graph by Continuously Plotting Arrays (Point/Line Plot) |
|
![]() |
Explains how to create 3D point/line graph animations by updating arrays over time. |
Animating a 2D Graph by Continuously Plotting Arrays |
|
![]() |
Explains how to create 2D graph animations by updating arrays over time. |
Plotting Arrays on a 3D Graph (Surface/Mesh Plot) |
|
![]() |
Explains how to plot coordinate data stored in an array on a 3D surface/mesh graph with sample code. |
Plotting a File on a 3D Graph (Surface/Mesh Plot) |
|
![]() |
Explains how to plot coordinate data from a file on a 3D surface/mesh graph with sample code. |
Plotting Arrays on a 3D Graph (Point/Line Graph) |
|
![]() |
Explains how to plot coordinate data stored in an array on a 3D graph with sample code. |
Plotting Arrays on a 2D Graph |
|
![]() |
Explains how to plot coordinate data stored in an array on a 2D graph with sample code. |
Plotting a File on a 3D Graph (Point/Line Graph) |
|
![]() |
Explains how to plot coordinate data from a file on a 3D graph with sample code. |
Plotting a File on a 2D Graph |
|
![]() |
Explains how to plot coordinate data from a file on a 2D graph with sample code. |