How can one draw "regular" 3D surface plot in Asymptote
from data.csv
?
Following (I dare to say basic) code with the help of pgfplots
does the job (suppose you have optimal data format):
\documentclass[12pt]{article}
\begin{document}
\begin{figure}
\begin{tikzpicture}
\begin{axis}[colorbar]
\addplot3 [
surf,
mesh/ordering=y varies,
mesh/cols=15,
] table [col sep=comma,] {data.csv};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}
To my basic knowledge, only mesh/cols has to be set-up for given data set. Is there any -almost- general approach also in Asymptote
?
NOTES:
Why Asymptote: Pgfplots are great Latex package, fun to use with great documentation and tutorials. However, even when I compile with LuaLaTeX, I am worried about performance - I expect that I will generate several 3D plots with more than 1 000 points, with might take long. Also very big feature is .prc format, which I would like to be able to utilize.
Why generic: I am still learning LaTeX, programming (mostly in python) and Asymptote syntax seems to me hard to grasp. There is great tutorial from Mr. Staats, and "package documentation," but they dont seem to cover my situation (or am I mistaken?) and I am not sure that I am up to learn Asymptote syntax ...
Final note: If there is no general approach, which could be easily utilized, as with pgfplots code above, please inform me (than this question might become off-topic, if it is not already) or, if there is the file data.csv
needed, I will upload sample data.
Regards, Tomas
EDIT: Uploaded sample data.csv
here (google drive)
I have to admit I lack knowledge of terminology in 3D graph creation. I have data structured in I would call a matrix - for each value of x
, there is y
changing by constant value and finally value of z
. This information is passed to pgfplots package in the code above by lines
mesh/ordering = y varies,
mesh/cols = 15
I think I understand the code in the example as far as this:
//Necessary module imports
import three;
import grid3;
bool renderPRC = true; //Pretty essential for me, I would like to obtain graph in PRC format
if(renderPRC) {
// PRC TRUE
settings.prc=true;
settings.embed=true;
}
else {
// RASTERIZE
settings.outformat="png";
settings.prc=false;
settings.render=3;
}
file in=input(data.csv).line().csv(); // I am not sure, if "data" should be with ".csv" or not
real[][] a=in.dimension(0,0); //Initiation of array a with data collection until the end of file
real[] x=a[0];
real[] y=a[1];
real[] z=a[2]; // Assignment of values from array a to x, y, z arrays; depending on column index? (data.csv has 3 columns)
//if I understood correctly, next are pen settings, which I think I dont need except for any contour, that would emphasize the "z" value.
Next goes surface part, which is beyond my knowledge.
Remark: I looked closely in linked answer at solution with triangulation:
How to plot a surface from a set of data?
As I dont have enough of a education/knowledge in mathematics, understanding of that is (now) beyond me, but I see that data in that answer resemble mine by theyre structure. I have also tested triangulation approach to create 3D graph with python and matplotlib, using its triangulation (ref: https://python-graph-gallery.com/371-surface-plot/).
Is that simillar to Asymptote
and can answer from user g.kov be used also in my case? I test it as soon as I will have access to Asymptote
and test it further (and edit the question again if needed).
real[][]
. This is not difficult (although it can be difficult to remember the boilerplate). 2) Turn your array of 3d points into a surface. This requires some extra work in Asymptote. Most of the code in the linked answer is trying to deal with this second step.