Take the 2-minute tour ×
TeX - LaTeX Stack Exchange is a question and answer site for users of TeX, LaTeX, ConTeXt, and related typesetting systems. It's 100% free, no registration required.

I am trying to learn how to use pgfplots by plotting simple things, like a two-dimensional sphere. However, I find it quite surprising that depending on the view angle, the result sometimes does not look like a sphere at all. Unless I am missing something, a sphere should like the same no matter which direction we are looking from.

Here is my example code:

\documentclass[a4paper,landscape]{article}

\usepackage{tikz}
\usepackage{pgfplots}

\pgfplotsset{width=6cm}

\newcommand{\degree}{\ensuremath{^\circ}}
\newcommand{\plotsphere}[2]{
\begin{axis}[view={#2}{#1},axis equal,title={$\theta=#1\degree,\quad \phi=#2\degree$}]
\addplot3[surf,shader=flat,z buffer=sort,
samples=20,domain=-1:1,y domain=0:2*pi]
({sqrt(1-x^2) * cos(deg(y))},
{sqrt( 1-x^2 ) * sin(deg(y))},
x);
\end{axis}
}

\begin{document}
\pagestyle{empty}
\begin{figure}
\begin{tikzpicture}[scale = 0.75]
\foreach \x/\polangle in {-8/20,0/45,8/70}
    \foreach \y / \azangle in {-8/20,0/45,8/70}
        \node at (\x,\y) {\plotsphere{\polangle}{\azangle}};
\end{tikzpicture}
\end{figure}
\end{document}

and the result:

enter image description here

The only version I am satisfied with is view={45}{45}. All the other ones appear distorted. It seems that this distortion does not come from different length units on the axis because I am using the axis equal option. Am I forgetting some important parameter?

share|improve this question
    
Actually they are distorted, look at the tick marks. Try axis equal image. –  zeroth Sep 29 '12 at 21:59
    
@zeroth please turn your comment into an answer, with a few screenshots to demonstrate :) –  cmhughes Sep 30 '12 at 5:44
    
@cmhughes at the time of writing I did not know if it would help. I will apply some tests. Thanks! –  zeroth Sep 30 '12 at 7:19
2  
Update the package. In the current version (1.6), this bug has been fixed. –  Luigi Sep 30 '12 at 9:04
    
@zeroth With the version of pgfplots (1.5.1) I had, using axis equal image didn't solve the problem, but upgrading to (1.6) as @Luigi suggested solves the problem, thank you very much (then I can use any axis scaling as illustrated in your answer). –  Corentin Sep 30 '12 at 16:06
show 1 more comment

1 Answer 1

up vote 6 down vote accepted

As Luigi correctly states, it was a bug which has been fixed in the 1.6 version.

Therefore an update will solve your problem. For the record try and see the difference between axis equal and axis equal image in the following figures.

No axis scaling

Of course here the scaling is wrong.

enter image description here

axis equal option

Here the scaling is correct. It will scale the axis limits so that it keeps the width and height that has been specified (that is <axis>min and <axis>max are subjected to the scaling). Hence you will see that it has tendencies to fill with a lot of white space if one does not have correct spacings (notice that in \theta=45).

enter image description here

axis equal image option

The scaling is also correct here. However, here the <axis>min and <axis>max are not the scaling parameters. Instead the width and height of the image is matched that of the found <axis>min and <axis>max lengths. Thus the image size will not be retained, even if specified.

enter image description here

share|improve this answer
    
Thanks for this detailed post. I still don't get it though. I experience something like in the lower right examples with my own code, too. So how do I get the effect of axis equal image but with a fixed size of the picture produced? –  Christian May 16 '13 at 1:43
    
@Christian in that case I would rely on the axis equal and then fit your own size. This does what you want, I suppose (I am not really clear what you have done etc.) –  zeroth May 19 '13 at 11:11
    
No, I don't want the white space that this gives me. I ended up adjusting the viewing angle so that the size more or less fits. I still have one rather high plot that doesn't fill the page width but I guess I can live with that. I still think this part of pgfplots could be more intuitive :/ –  Christian May 19 '13 at 11:53
1  
Ah, I think I know what you meant now. Ok, yes, this is not trivially done. 3D in TeX is cumbersome... ;) –  zeroth May 19 '13 at 11:56
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.