Today I have a question about scatter plots:
Is it possible to interpolate scatter plots?
In my work I often use "intensity plots" (that's how we call them). In these plots x and y are positions, while the color of a point is determined by the intensity. This kind of plot can be created using a 3D-surface plot and setting view={0}{90}
. The result can be seen in the right plot. The left plot shows the corresponding scatter plot.
Since 3D plots take a long time to create (to cite the pgfplots manual:"pgfplots’ three dimensional routines are slow"), especially for larger datasets, and since I actually don't want a 3D plot, I would like to know wheter there is a way to make the scatter plot on the left look like the 3D plot on the right.
Here is the code for my example:
\documentclass[crop,10pt]{standalone}
\usepackage[english]{babel}
\usepackage{pgfplots}
\usepgfplotslibrary{units}
\begin{document}%
\setlength{\textwidth}{246pt}%
\setlength{\linewidth}{246pt}%
\begin{tikzpicture}
\begin{axis}
\addplot+[scatter,scatter src=explicit,mark=square*,only marks]
coordinates {
(0,0) [0]
(0,1) [1]
(0,2) [2]
(0,3) [3]
(1,0) [4]
(1,1) [5]
(1,2) [6]
(1,3) [7]
(2,0) [8]
(2,1) [9]
(2,2) [10]
(2,3) [11]
};
\end{axis}
\end{tikzpicture}
\begin{tikzpicture}
\begin{axis}[view={0}{90}]
\addplot3[surf,shader=interp]
coordinates {
(0,0,0) (1,0,4) (2,0,8)
(0,1,1) (1,1,5) (2,1,9)
(0,2,2) (1,2,6) (2,2,10)
(0,3,3) (1,3,7) (2,3,11)
};
\end{axis}
\end{tikzpicture}
\end{document}
Thanks for your help,
John
Best Answer
Let me try to summarize what I gathered from your question and from your comments:
you have some 3d visualization which requires lots of time.
"lots of" means 1000+ data points. This corresponds to a resolution of ~ 30x30
you are wondering how to improve speed; and scatter plots appeared to be a solution.
First, concerning (3.): if you need scatter plots, there is not much choice, I guess. But if you really have the choice, you should stick with
surf, shader=interp
. This surface plot handler can be processed efficiently by pgfplots; it is much faster than scatter plots and it results in a smaller pdf. And: if you have a relatively smooth function, it requires few data points.Concerning the need to improve compilation times: I think there are three choices:
choice 1: the
external
library. Writeinto your preamble; then compile with
pdflatex -shell-escape
. This allows automatic export of individual pictures to pdf, with sophisticated logic to preserve scaling, alignment, bounding boxes, labels, etc. You can find lots of instructions in the manual or on this site.choice 2: the standalone package can also be used. Details in the manual or on this site.
choice 3: if even the compilation of these external pdfs takes too long, you can consider reducing the sampling resolution. Perhaps this is feasible.
If the quality degenerates but you know that you surface is smooth, you could even resort to the
patchplots
lib of pgfplots and use some higher-order shader (patch type=bilinear
orpatch type=biquadratic
orpatch type
=bicubiccombined with
shader=interp). Except for
patch type=bilinear, these patches require changes to your sampling routine (i.e. the expected input changes). See also
patch type sampling` in pgfplots 1.7.choice 4: you can resort to
\addplot graphics
. The\addplot graphics
switch, however, should be regarded as last hope as it involves more manual work (tuning axis limits) than desired and involves 3rd party tools (more overhead).