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 build a 3 dimension graph using the following code.

\documentclass{article}

\usepackage{pgfplots}

\begin{document}

\begin{figure} [H]
\centering
\pgfplotsset{compat=newest}
\begin{tikzpicture} [scale=0.8]
\begin{axis}[
view = {5}{8},
grid=both,
legend cell align=left,
xticklabels = {10,20,30,40,50,60,70,80,90,100,110},
yticklabels ={0.03,0.05,0.07,0.09,0.11,0.13,0.23,0.33,0.43,0.53},
zticklabels = {0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1},
xtick={1,2,3,4,5,6,7,8,9,10,11},
ytick={1,2,3,4,5,6,7,8,9,10},
tick label style={font=\tiny},
legend pos=north east,
legend columns = 4,
y tick label style={rotate=90},
ylabel=distinctness,
xlabel=Dimension,
zlabel=silhouette coefficient,
y label style={rotate=57},
]
\addplot3  coordinates{(1,1,0.27)(1,2,0.27)(1,3,0.27)(1,4,0.27)(1,5,0.32)(1,6,0.38)   (1,7,0.66)(1,8,0.80)(1,9,0.80)(1,10,0.85)};
\addplot3  coordinates{(2,1,0.23)(2,2,0.30)(2,3,0.33)(2,4,0.40)(2,5,0.46)(2,6,0.43)(2,7,0.62)(2,8,0.80)(2,9,0.85)(2,10,0.87)};
\addplot3  coordinates{(3,1,0.83)(3,2,0.85)(3,3,0.86)(3,4,0.86)(3,5,0.86)(3,6,0.57)(3,7,0.74)(3,8,0.78)(3,9,0.86)(3,10,0.87)};
\addplot3  coordinates{(4,1,0.86)(4,2,0.88)(4,3,0.90)(4,4,0.56)(4,5,0.56)(4,6,0.52)(4,7,0.64)(4,8,0.78)(4,9,0.84)(4,10,0.87)};
\addplot3  coordinates{(5,1,0.92)(5,2,0.92)(5,3,0.52)(5,4,0.57)(5,5,0.59)(5,6,0.58)(5,7,0.63)(5,8,0.81)(5,9,0.82)(5,10,0.85)};
\addplot3  coordinates{(6,1,0.86)(6,2,0.90)(6,3,0.91)(6,4,0.85)(6,5,0.86)(6,6,0.87)(6,7,0.88)(6,8,0.80)(6,9,0.82)(6,10,0.86)};
\addplot3  coordinates{(7,1,0.83)(7,2,0.87)(7,3,0.88)(7,4,0.88)(7,5,0.86)(7,6,0.86)(7,7,0.83)(7,8,0.79)(7,9,0.84)(7,10,0.86)};
\addplot3  coordinates{(8,1,0.66)(8,2,0.76)(8,3,0.76)(8,4,0.76)(8,5,0.79)(8,6,0.80)(8,7,0.68)(8,8,0.81)(8,9,0.84)(8,10,0.85)};
\addplot3  coordinates{(9,1,0.79)(9,2,0.84)(9,3,0.56)(9,4,0.59)(9,5,0.63)(9,6,0.65)(9,7,0.73)(9,8,0.80)(9,9,0.84)(9,10,0.85)};
\addplot3  coordinates{(10,1,0.36)(10,2,0.52)(10,3,0.52)(10,4,0.59)(10,5,0.63)(10,6,0.64)(10,7,0.73)(10,8,0.80)(10,9,0.84)(10,10,0.86)};
\addplot3  coordinates{(11,1,0.36)(11,2,0.52)(11,3,0.52)(11,4,0.59)(11,5,0.63)(11,6,0.64)(11,7,0.73)(11,8,0.80)(11,9,0.84)(11,10,0.86)};
\end{axis}
\end{tikzpicture}
\end{figure}
\end{document}

enter image description here

There are some issues with it, may be many, you can suggest what other changes can I make so that the plot is more illustrative. Issues that I know of but don't know how to solve:

  1. How can I increase the length of y-axis so that all the ticks and labels are clearly readable like the labels of x-axis
  2. How can I show all the ticks for z-axis, I wrote zticklabels = {0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1} in my code, but the plot does not show all the values. What is going wrong here?

  3. What is the meaning of view attribute? I know changing the values changes the orientation of plot along the z-axis. But what I don't understand is how it works, means, I don't know what value of views will bring what kind of effect?

I will appreciate any suggestion that you can provide. Thanks.

share|improve this question
1  
Welcome to TeX.sx! As a new user without image posting privileges simply include the image as normal and remove the ! in front of it to turn it into a link. A moderator or another user with edit privileges can then reinsert the ! to turn it into an image again. –  Torbjørn T. Jan 25 '12 at 17:06
2  
IMHO: this kind of graph should not be done in 3D, even when the view is at the correct position. The view attribute tells tikz where the "camera" is located in 3D space (spherical coordinates, if I'm not mistaken). The problem is that for points drawn floating in a 3D axis it's hard to see what the values on the axes are. I would suggest you use several stacked (2D) surface plots, perhaps using opacity. Even this could become cluttered though, since there are so many surfaces. Perhaps it would be best to try a singe (3D) surface plot of all your data? Note that this is purely an opion. –  romeovs Jan 25 '12 at 18:10
add comment

1 Answer 1

up vote 6 down vote accepted
  • Point 1: use the key plot box ratio.
  • Point 2: a workaround is to give explicitly the ticks as you did for x and y axis. However, they are not all there, I need to dig more in the manual.
  • Suggestion: use the sloped key to avoid the need to give an explicit angle to the rotation of the y label (that value might change with other views).

enter image description here

\documentclass{standalone}
\usepackage{pgfplots}
\begin{document}
\pgfplotsset{compat=newest}
\begin{tikzpicture}
\begin{axis}[
plot box ratio = 1 3 1,
view = {5}{8},
grid = both,
xticklabels = {10,20,30,40,50,60,70,80,90,100,110},
yticklabels = {0.03,0.05,0.07,0.09,0.11,0.13,0.23,0.33,0.43,0.53},
zticklabels = {0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1},
xtick = {1,2,3,4,5,6,7,8,9,10,11},
ytick = {1,2,3,4,5,6,7,8,9,10},
ztick = {0.1,0.2,0.3,0.4,0.5,0.6,0.7,0.8,0.9,1},
tick label style = {font=\tiny},
y tick label style = {rotate=90},
xlabel = Dimension,
ylabel = distinctness,
zlabel = silhouette coefficient,
y label style = sloped,
]
\addplot3  coordinates{(1,1,0.27)(1,2,0.27)(1,3,0.27)(1,4,0.27)(1,5,0.32)(1,6,0.38)   (1,7,0.66)(1,8,0.80)(1,9,0.80)(1,10,0.85)};
\addplot3  coordinates{(2,1,0.23)(2,2,0.30)(2,3,0.33)(2,4,0.40)(2,5,0.46)(2,6,0.43)(2,7,0.62)(2,8,0.80)(2,9,0.85)(2,10,0.87)};
\addplot3  coordinates{(3,1,0.83)(3,2,0.85)(3,3,0.86)(3,4,0.86)(3,5,0.86)(3,6,0.57)(3,7,0.74)(3,8,0.78)(3,9,0.86)(3,10,0.87)};
\addplot3  coordinates{(4,1,0.86)(4,2,0.88)(4,3,0.90)(4,4,0.56)(4,5,0.56)(4,6,0.52)(4,7,0.64)(4,8,0.78)(4,9,0.84)(4,10,0.87)};
\addplot3  coordinates{(5,1,0.92)(5,2,0.92)(5,3,0.52)(5,4,0.57)(5,5,0.59)(5,6,0.58)(5,7,0.63)(5,8,0.81)(5,9,0.82)(5,10,0.85)};
\addplot3  coordinates{(6,1,0.86)(6,2,0.90)(6,3,0.91)(6,4,0.85)(6,5,0.86)(6,6,0.87)(6,7,0.88)(6,8,0.80)(6,9,0.82)(6,10,0.86)};
\addplot3  coordinates{(7,1,0.83)(7,2,0.87)(7,3,0.88)(7,4,0.88)(7,5,0.86)(7,6,0.86)(7,7,0.83)(7,8,0.79)(7,9,0.84)(7,10,0.86)};
\addplot3  coordinates{(8,1,0.66)(8,2,0.76)(8,3,0.76)(8,4,0.76)(8,5,0.79)(8,6,0.80)(8,7,0.68)(8,8,0.81)(8,9,0.84)(8,10,0.85)};
\addplot3  coordinates{(9,1,0.79)(9,2,0.84)(9,3,0.56)(9,4,0.59)(9,5,0.63)(9,6,0.65)(9,7,0.73)(9,8,0.80)(9,9,0.84)(9,10,0.85)};
\addplot3  coordinates{(10,1,0.36)(10,2,0.52)(10,3,0.52)(10,4,0.59)(10,5,0.63)(10,6,0.64)(10,7,0.73)(10,8,0.80)(10,9,0.84)(10,10,0.86)};
\addplot3  coordinates{(11,1,0.36)(11,2,0.52)(11,3,0.52)(11,4,0.59)(11,5,0.63)(11,6,0.64)(11,7,0.73)(11,8,0.80)(11,9,0.84)(11,10,0.86)};
\end{axis}
\end{tikzpicture}
\end{document}
  • Point 3: In the following image, different values of the key view.

enter image description here

share|improve this answer
    
Thanks you so much @cjrossen. As a gesture of thanks, I can only wish for you now, may god bless you with all your desires. –  user11158 Jan 26 '12 at 5:47
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.