The problem is caused by the fact that pgfplots did not properly respect the 'raw gnuplot' option in one place: it used its own keys samples
and samples y
to determine the input matrix size, but it does not communicate them to gnuplot.
The developer version of pgfplots now contains a bugfix for this behavior.
Until this version becomes stable, I can offer you a (very simple) work-around (see below).
However, you still need to communicate the sample counts to gnuplot (in case of raw gnuplot
, pgfplots assumes that you take full responsability).
Both these things can be acomplished using
\addplot3[raw gnuplot,
surf,
%empty line = jump,
samples=25, %---
samples y=50, %---
]
gnuplot[surf,
%mesh/check=false,
]{
n=1e-5;
b=100;
h=10;
p=-0.0001;
set samples 25,50; %---
set isosamples 25,50; %---
K=((16*b**2)/(n*pi**3))*(-p);
Sum(i,x,y)=K*(((-1)**(0.5*((2*i-1)-1)))*(1-((cosh(((2*i-1)*pi*x)/(2*b)))/(cosh(((2*i-1)*pi*h)/(2*b)))))*((cos(((2*i-1)*pi*y)/(2*b)))/((2*i-1)**3)));
u(i,x,y)=(i==0)?0:(u(i-1,x,y)+Sum(i,x,y));
splot [-h:h] [-b:b] u(25,x,y)/u(25,0,0);
};
the (pgfplots) key samples=<x>
must match the first argument of set isosamples=<x>, <y>
and the (pgfplots) key samples y=<y>
must match the second argument. I honestly do not know how to combine the gnuplot options set samples
and set isosamples
- I suppose set samples
is unnecessary here. This should (generally) solve this bug.
I strongly recommend to uncomment mesh/check=false
(it indicates that pgfplots could not read the matrix structure).
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. Write
\usetikzlibrary{external}
\tikzexternalize
into 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
or patch type=biquadratic
or patch 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).
Best Answer
It uses cubic bézier curves to connect the points of your plot, with the two supports for each point calculated using a relatively simple algorithm that takes the previous and next point into account.